Wordpress widget title - php

Is there a way to have individual title widget to have a link of their own without using a plugin?
register_sidebar( array(
'name' => __( 'Footer', 'classic' ),
'id' => 'sidebar-3',
'description' => __( 'An optional widget area for your site footer', 'classic' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );

There is no other way than to use a plugin but I refuse to do so. So I have used jQuery to trigger the widget title with specific id and added a link.
$("#menu1 h3").wrap('');

Related

How to register sidebar wordpress

I'm making a wordpress template and needed to register a sidebar. i used the function register_sidebar() to do it and it works but it seems to make a conflict with the default sidebar of wordpress. The default sidebar appeared as inactive. how do i register the default wordpress sidebar?
my code in functios.php
function wpb_init_widgets($id) {
register_sidebar(array(
'name' => 'Sidebar-1',
'id' => 'sidebar-1',
'before_widget' => '<div class="sidebar-module">',
'after_widget' => '</div>',
'before_title' => '</h4>',
'after_title' => '</h4>'
));
}
add_action('widgets_init','wpb_init_widgets');
thanks in advance.
Try editing your code like this:
function wpb_init_widgets_custom($id) {
register_sidebar(array(
'name' => 'Customsidebar-1',
'id' => 'customsidebar-id',
'before_widget' => '<div class="sidebar-module">',
'after_widget' => '</div>',
'before_title' => '</h4>',
'after_title' => '</h4>'
));
}
add_action('widgets_init','wpb_init_widgets_custom');
For the ID, you need to use -id as If you do not set the id argument value, you will get E_USER_NOTICE messages in debug mode. Also the ID sidebar-1 is taken by many themes so it might cause a conflict.
Let me know if this helped and whether the default sidebar is still inactive.As Leland suggested, also try changing the functions name, that might be the cause of the conflict too, maybe even more likely than what I wrote above. So the new function name is changed to wpb_init_widgets_custom.
Try to do like this
add_action( 'widgets_init', 'function_widgets_init' );
function function_widgets_init()
{
register_sidebar( array (
'name' => __( 'Sidebar Widget Area', 'textdomain' ),
'id' => 'primary-widget-area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}

How To Add a Class To a Custom Sidebar in WordPress

I just learned how to create a custom WordPress theme. I would like to assign a class to my sidebar for styling, but I have not found anything online that explains how to do this. The code I added to my functions.php file to register my sidebar is:
if ( function_exists('register_sidebar') )
register_sidebar(array(
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
And the code I added to my sidebar.php file is:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
Any help would be greatly appreciated!
Use before_widget and after_widget to add a wrapper.
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => 'Add widgets here to appear in your sidebar.',
'before_widget' => '<aside id="%1$s" class="widget custom-class %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title custom-class">',
'after_title' => '</h2>',
) );
Try this in functions.php file

Functions.php - Wordpress

I want to change the H1 to H2 in the functions.php from my wordpress site.
I have a child theme. But when I past the code in the functions.php from my child theme I get a fatal error:
/data/home/secr02/domains/secretsistersblog.com/public_html/wp-content/themes/twentyfourteen-child/functions.php:9) in /data/home/secr02/domains/secretsistersblog.com/public_html/wp-content/themes/twentyfourteen/functions.php on line 197"
I searched on the internet and I think I have to perform a remove action first.
But I have little knowledge of php.
Can somebody maybe help me?
This is what is in the original functions.php:
function twentyfourteen_widgets_init() {
require get_template_directory() . '/inc/widgets.php';
register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
register_sidebar( array(
'name' => __( 'Primary Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-1',
'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Content Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-2',
'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
Thanks.
Johanna
You can do something like this:-
Add below code in your child theme's functions.php file and add/change code in my_widgets_init function according your desire.
//First Remove Old Action Hook.
remove_action('widgets_init', 'twentyfourteen_widgets_init');
//Register your own hook.
add_action('widgets_init', 'my_widgets_init');
function my_widgets_init()
{
/**
* Add Or Modify Your Code In This Function.
*/
/***Updated Code***/
//require get_template_directory() . '/inc/widgets.php';
//register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
register_sidebar( array(
'name' => __( 'Primary Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-1',
'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Content Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-2',
'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}

how to add nl2br function to sidebar

I`m wondering, how to add function nl2br to my sidebar at WordPress.
Thing is, I add text widget to my sidebar and I want to change 'enter' to .
I know, that to register sidebar is code:
register_sidebar( array(
'name' => __( 'Footer First', 'myTheme' ),
'id' => 'sidebar-5',
'description' => __( 'Footer widget appears everywhere', 'myTheme' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
I was trying to add nl2br to before_widget, but it dont works... Probybly I need add function to my functions.php but I have no idea how to get content of my text widget.

Create widget area in wordpress dashboard pages section?

How to create a widget area in wordpress pages section. if I add below code in my functions.php file the widget created in dashboard menu section I want to add additional widget in my pages section not in dashboard.
Add a widget to the dashboard.
//This function is hooked into the 'wp_dashboard_setup' action below.
function example_add_dashboard_widgets() {
wp_add_dashboard_widget(
'example_dashboard_widget', // Widget slug.
'Example Dashboard Widget', // Title.
'example_dashboard_widget_function' // Display function.
);
}
add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' );
Create the function to output the contents of our Dashboard Widget.
function example_dashboard_widget_function() {
// Display whatever it is you want to show.
echo "Hello World, I'm a great Dashboard Widget";
}
you should register sidebar in functions.php as
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'widget_name',
'id' => 'widget-id',
'description' => 'Type something here',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}
it will register sidebar(widget) in your dashboard. Now you can you is it anywhere by
<?php dynamic_sidebar('widget-id'); ?>
This function already exists in default theme
function twentyfourteen_widgets_init() {
require get_template_directory() . '/inc/widgets.php';
register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
register_sidebar( array(
'name' => __( 'Primary Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-1',
'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Content Sidebar', 'twentyfourteen' ),
'id' => 'sidebar-2',
'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
you can create multiple widget area by copy and pasting this and chage the id every time
register_sidebar( array(
'name' => __( 'new area', 'twentyfourteen' ),
'id' => 'sidebar-5',
'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
In function.php add:
function create_widget($name, $id, $description) {
register_sidebar(array(
'name' => __( $name ),
'id' => $id,
'description' => __( $description ),
'before_widget' => '<div id="'.$id.'" class="widget %1$s %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
create_widget("Header", "uptop", "Displays in the header of the site, above the title"); // Create the actual widgets
Then add next code in place u wanna use this area, for example in your header.php:
<?php if ( !dynamic_sidebar('uptop') ); ?>

Categories