I have imported a theme and all is working well with Wordpress. However, I am trying to add a widget into the footer.php but for some reason this is not displaying.
My footer.php is as follows:-
<?php get_sidebar('footer_widget'); ?>
And I have added this into functions.php too
function bauhaus_arphabet_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'sidebar', 'bauhaus' ),
'id' => 'bauhaus_sidebar',
'before_widget' => '<div id="%1$s" class="widget sidebar_widget %2$s">',
'after_widget' => '</div>',
'description' => esc_html__( 'blog sidebar', 'bauhaus' ),
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Footer', 'bauhaus' ),
'id' => 'footer_widget',
'before_widget' => '<div id="%1$s" class="widget footer_widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>'
));
}
Does anyone have any idea why this is not displaying?
Thank you in advance,
Scott
Replace the code with :
<?php dynamic_sidebar( 'footer_widget' ); ?>
I have a html template and I have this code in my html and wants to convert this in wordpress
<div id="home">
<!-- Home Page -->
<p class="blue">NEED A DESIGNER?</p>
<p class="orange">I AM HERE</p>
<span><i class="fa fa-phone-square"></i> +1 234 567 876 54</span>
<!-- / Home Page -->
</div>
I want to call this as dynamic_sidebar(); ....
how i can register sidebar in functions.php file...
I tried as following
add_action( 'widgets_init', 'homepage_widget' );
function homepage_widget() {
register_sidebar( array(
'name' => __( 'main homepage', 'theme-slug' ),
'id' => 'homepagelol',
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
'class' => 'orange',
'before_widget' => '<div id="home">',
'after_widget' => '</div>',
'before_title' => '<p class="blue">',
'after_title' => '</div>',
) );
}
There are few steps you need to follow:
Step 1 : Register your sidebar
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'theme-slug' ),
'id' => 'sidebar-1',
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}
Step 2: In widget Area, you see your sidebar, then add text widget and put your html in text widget
Step 3: Then call your sidebar in index.php
<?php dynamic_sidebar('your-sidebar-unique-id'); ?>
Then save your page and reload..
Hope this will help you.
thanks
You can try this code to register sidebar, hope it helps.
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'MiddleSidebar',
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h3>',
));
register_sidebar(array('name'=>'FooterSidebar',
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h3>',
));
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>',
) );
}
Earlier in the afternoon, I had asked for a solution on how to echo different sidebars on different category pages of Wordpress which was solved. Now the problem which I am facing is that there's a continuous '1' being displayed under the sidebar on all the category pages. However, this isn't happening when I switch back to the old code which was displaying only one sidebar on all the category pages. Here's the code which was originally inside the sidebar.php file and which was echoing only one sidebar on all the pages:
<?php if ( is_active_sidebar( 'main_sidebar' ) ) : ?>
<div id="main_sidebar" class="widget-area">
<?php dynamic_sidebar( 'main_sidebar' ); ?>
</div><!-- #first_sidebar .widget-area -->
<?php endif; ?>
And this is the modified code which I have put inside the sidebar.php file which is echoing different sidebars on different category pages:
<?php if ( is_active_sidebar( "main_sidebar" ) ) : ?>
<div id="main_sidebar" class="widget-area">
<?php
if ( is_category( '7' )) {
echo dynamic_sidebar( 'category_fashion' );
}
elseif ( is_category( '1' )) {
echo dynamic_sidebar( 'category_music' );
}
elseif ( is_category( '5' )) {
echo dynamic_sidebar( 'category_tastemakers' );
}
elseif ( is_category( '11' )) {
echo dynamic_sidebar( 'category_film' );
}
elseif ( is_category( '9' )) {
echo dynamic_sidebar( 'category_model' );
}
elseif ( is_category( '6' )) {
echo dynamic_sidebar( 'category_sports' );
}
elseif ( is_category( '8' )) {
echo dynamic_sidebar( 'category_round' );
}
elseif ( is_category( '10' )) {
echo dynamic_sidebar( 'category_cool' );
}
else
{
echo dynamic_sidebar( 'main_sidebar' );
}
?>
</div><!-- #first_sidebar .widget-area -->
<?php endif; ?>
When I use the original code, the number '1' doesn't appear under the sidebar but when I switch to the code which I've modified, the number '1' starts to appear under the sidebar on all the pages. This behavior can be seen by going to this link: http://ignoremusic.com/category/sports/
I have also checked the archive.php file as well as the functions.php file but nothing seems to be wrong. Here's the part of the code which I've put inside the functions.php file to register the sidebars:
/** SIDEBARS ******************************************************************/
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'sidebar home left',
'id' => 'homeleft_sidebar',
'description' => __( 'sidebar on homepage, left', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Tastemakers',
'id' => 'category_tastemakers',
'description' => __( 'sidebar on tastemakers category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Film',
'id' => 'category_film',
'description' => __( 'sidebar on film category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Fashion',
'id' => 'category_fashion',
'description' => __( 'sidebar on fashion category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Model Citizens',
'id' => 'category_model',
'description' => __( 'sidebar on model citizens category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Sports',
'id' => 'category_sports',
'description' => __( 'sidebar on sports category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Round Table',
'id' => 'category_round',
'description' => __( 'sidebar on round table category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Cool Stuff',
'id' => 'category_cool',
'description' => __( 'sidebar on cool stuff category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Music',
'id' => 'category_music',
'description' => __( 'sidebar on music category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar home right',
'id' => 'homeright_sidebar',
'description' => __( 'sidebar on homepage, right', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'main sidebar',
'id' => 'main_sidebar',
'description' => __( 'main sidebar', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'tour dates sidebar',
'id' => 'tour_sidebar',
'description' => __( 'sidebar on tour dates page', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'contact sidebar',
'id' => 'contact_sidebar',
'description' => __( 'sidebar on contact page', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 1',
'id' => 'sidebarf1',
'description' => __( 'first sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 2',
'id' => 'sidebarf2',
'description' => __( 'second sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 3',
'id' => 'sidebarf3',
'description' => __( 'third sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 4',
'id' => 'sidebarf4',
'description' => __( 'fourth sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
}
And this is the code inside the archives.php file which is echoing the sidebar:
<div id="sidebar" class="grid_3">
<?php get_sidebar(); ?>
</div><!-- #sidebar-->
I tried searching for the problem on the internet but couldn't find anything so I look forward to hear from you guys. Thank you.
According to https://codex.wordpress.org/Function_Reference/dynamic_sidebar it should be
dynamic_sidebar( 'category_fashion' );
instead of echo dynamic_sidebar( 'category_fashion' );
The function probably returns true; echo takes a string; true->string=1, therefore the additional 1.
Superfluous echo, caused by confusion, caused by silly Wordpress functions that print things rather than returning them.
In your case, the following is at fault:
<?php echo dynamic_sidebar( 'category_fashion' ); ?>
Contrast with your earlier and correct usage:
<?php dynamic_sidebar( 'main_sidebar' ); ?>
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('');