Tagged: widgets
- This topic has 17 replies, 4 voices, and was last updated 8 years, 6 months ago by marie21.
-
AuthorPosts
-
November 30, 2015 at 11:33 am #80405cytorath18Participant
Hello again.
Came across another issue here – I’m having difficulty adding a working widget area after the catchbase header. I wish to add a revolution slider widget here, but have been unsuccessful in my attempts.
So far, I’ve added a variety of widget areas – none of which add below the header any working widget.
// Adds a widget area. if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Extra Header Widget Area', 'id' => 'extra-widget-area', 'description' => 'Extra widget area after the header', 'before_widget' => '<div class="widget my-extra-widget">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>' )); } // Place the widget area after the header in home page only add_action ('__after_header', 'add_my_widget_area', 10); function add_my_widget_area() { if ( tc__f('__is_home') && function_exists('dynamic_sidebar') ) { dynamic_sidebar('Extra Header Widget Area'); } } function my_widgets_init() { register_sidebar( array( 'name' => __( 'Main Sidebar', 'your-theme' ), 'id' => 'sidebar-1', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => "</div>", 'before_title' => '<h3>', 'after_title' => '</h3>', ) ); register_sidebar( array( 'name' => __( 'Header Area', 'your-theme' ), 'id' => 'sidebar-2', 'description' => __( 'An optional widget area for your site header', 'your-theme' ), 'before_widget' => '<div id="%1$s" class="headwidget %2$s">', 'after_widget' => "</div>", 'before_title' => '<h3>', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'my_widgets_init' ); // Add a widget. if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Try This After Header', 'id' => 'extra-widget', 'description' => 'After Header', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>' )); } // Place the widget after the header add_filter ('__after_header', 'add_my_widget'); function add_my_widget() { if (function_exists('dynamic_sidebar')) { dynamic_sidebar('Try This After Header'); } }
Any advice? I’ve also used the ‘before post’ widget which worked, but showed the slider three times no matter what I tried.
November 30, 2015 at 8:01 pm #80425PratikParticipantHi @cytorath18,
If you want to make changes to the code, make sure you make the edits via Child Theme. To know more about Child Themes goto link: Child Theme Tutorial . Then download the child theme for Catch Base.
After this, in the child theme’s functions.php add following code:
/** * Register extra custom widgetized area */ function catchbase_extra_header_widget_init() { //Extra Header Widget Area register_sidebar( array( 'name' => __( 'Extra Header Widget Area', 'catch-base' ), 'id' => 'extra-header-widget-area', 'before_widget' => '<section id="%1$s" class="widget %2$s"><div class="widget-wrap">', 'after_widget' => '</div><!-- .widget-wrap --></section><!-- #widget-default-search -->', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', 'description' => __( 'This is the extra header sidebar widget area that appears in homepage only.', 'catch-base' ), ) ); } add_action( 'widgets_init', 'catchbase_extra_header_widget_init' ); /** * Add Extra Header Widget Area below header#masthead */ function catchbase_extra_header_sidebar() { global $wp_query; // Get Page ID outside Loop $page_id = $wp_query->get_queried_object_id(); // Front page displays in Reading Settings $page_for_posts = get_option('page_for_posts'); if ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) ) { dynamic_sidebar('extra-header-widget-area'); } }
This will make the Widget Area appear just below header in home page. If you want it to appear elsewhere, edit the conditions
if ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) )
.However, if you are not familiar with this, it is highly recommended that you hire a customizer to do this work because this may cause some design issues which is beyond the Theme support scope.
December 2, 2015 at 1:09 am #80474cytorath18ParticipantI followed your directions, and the widget area appeared in the widgets page. However, when placing in the Rev Slider widget and saving it, I refreshed my homepage and nothing happened. The slider did not appear, and the page looked the same as it did before. Hm.
December 2, 2015 at 6:37 am #80495PratikParticipantHi @cytorath18,
Can you post your site url so i can check it?December 2, 2015 at 11:27 pm #80539cytorath18ParticipantI’m editing my site offline via Bitnami. I’ll see if I can maybe get it put up temporarily at a free hosting site.
December 5, 2015 at 3:02 am #80654cytorath18ParticipantI’ve uploaded a copy of my site so far to this link. Let me know if you need any further info.
December 5, 2015 at 9:04 am #80669PratikParticipantCan you add following code just at the end of the code I provided:
add_action( 'catchbase_header', 'catchbase_extra_header_sidebar', 110);
I am hopeful that this will add the sidebar just below the header above the primary menu.If you want it below the header-image, add following code:
add_action( 'catchbase_before_content', 'catchbase_extra_header_sidebar', 15);
December 7, 2015 at 4:34 pm #80779cytorath18ParticipantYour second suggestion worked like a charm. Thanks! đ
December 8, 2015 at 9:29 am #80797PratikParticipantHi cytorath18,
Great. I am glad everything worked out. It would be nice if you could leave a review for this theme at https://wordpress.org/support/view/theme-reviews/catch-base.Have a nice day.
Thanks
December 15, 2015 at 4:40 pm #81198NickBallDesignParticipantThis has almost worked for me, but I am wanting to add the extra area ‘within’ the header section (to the left of the social icons) I have been through every file to try and find where to edit, but the header.php is structured differently to other WordPress themes. I just want to add a line of text in the header.
December 16, 2015 at 4:27 pm #81234PratikParticipanthi @NickBallDesign,
Instead of the given add_action() code, use the following one:
add_action( 'catchbase_header', 'catchbase_extra_header_sidebar', 55);
This will add it to the left of social icon.
June 14, 2016 at 6:23 pm #93567marie21ParticipantHi Pratik,
I tried this for the catch-responsive theme with replace “catchbase” as “catschresponsive” but I cannot see this widget in âAppearance => Widgetsâ.
/**
* Register extra custom widgetized area
*/
function catchresponsive_extra_header_widget_init() {
//Extra Header Widget Area
register_sidebar( array(
‘name’ => __( ‘Extra Header Widget Area’, ‘catchresponsive’ ),
‘id’ => ‘extra-header-widget-area’,
‘before_widget’ => ‘<section id=”%1$s” class=”widget %2$s”><div class=”widget-wrap”>’,
‘after_widget’ => ‘</div><!– .widget-wrap –></section><!– #widget-default-search –>’,
‘before_title’ => ‘<h4 class=”widget-title”>’,
‘after_title’ => ‘</h4>’,
‘description’ => __( ‘This is the extra header sidebar widget area that appears in homepage only.’, ‘catchresponsive’ ),
) );
}
add_action( ‘widgets_init’, ‘catchresponsive_extra_header_widget_init’ );/**
* Add Extra Header Widget Area below header#masthead
*/
function catchresponsive_extra_header_sidebar() {
global $wp_query;// Get Page ID outside Loop
$page_id = $wp_query->get_queried_object_id();// Front page displays in Reading Settings
$page_for_posts = get_option(‘page_for_posts’);if ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) ) {
dynamic_sidebar(‘extra-header-widget-area’);
}
add_action( ‘catchresponsive_header’, ‘catchresponsive_extra_header_sidebar’, 55);
}What did I do wrong?
June 14, 2016 at 7:42 pm #93573marie21ParticipantUpdate: I found the widget in WordPress-Admin Content “Widgets” an add a “Textbox” to the Widget.
Unfortunately it´s not shown in the header đ
How can I change it to be shown on all pages?
June 15, 2016 at 9:25 am #93607PratikParticipant@marie21: There is a small issue with the code. The last line should be
add_action( âcatchresponsive_headerâ, âcatchresponsive_extra_header_sidebarâ, 55);
before}
So your final code becomes as follows:
/** * Register extra custom widgetized area */ function catchresponsive_extra_header_widget_init() { //Extra Header Widget Area register_sidebar( array( 'name' => __( 'Extra Header Widget Area', 'catchresponsive' ), 'id' => 'extra-header-widget-area', 'before_widget' => '<section id="%1$s" class="widget %2$s"><div class="widget-wrap">', 'after_widget' => '</div><!â .widget-wrap â></section><!â #widget-default-search â>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', 'description' => __( 'This is the extra header sidebar widget area that appears in homepage only.', 'catchresponsive' ), ) ); } add_action( 'widgets_init', 'catchresponsive_extra_header_widget_init' ); /** * Add Extra Header Widget Area below header#masthead */ function catchresponsive_extra_header_sidebar() { global $wp_query; // Get Page ID outside Loop $page_id = $wp_query->get_queried_object_id(); // Front page displays in Reading Settings $page_for_posts = get_option('page_for_posts'); if ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) ) { dynamic_sidebar('extra-header-widget-area'); } } add_action( 'catchresponsive_header', 'catchresponsive_extra_header_sidebar', 55);
Let me know how it goes.
Regards,
PratikJune 15, 2016 at 1:38 pm #93637marie21ParticipantHello Pratik,
thank you very much for your fast reply.
đ YES-It works!!!
How can I display this widget on all pages (not only home) and I need a little help with the position. It´s just below the logo and it will not switch to the right site of the header.
Regards
June 15, 2016 at 7:43 pm #93655marie21ParticipantUpdate: I found it already with this “all pages …”
if ( is_page() || is_category( $category ) ) {
dynamic_sidebar(‘extra-header-widget-area’);
}But I have no idea to show this widget on the right site in the header-area.
Regards
June 16, 2016 at 10:16 am #93670PratikParticipant@marie21:
If you want the widget to show on right side, then you will need to upgrade to pro version. Header right sidebar is a pro feature. I recommend you to upgrade to Pro version.Regards,
PratikJune 16, 2016 at 3:20 pm #93697marie21ParticipantHi Pratik,
so after new hours of try&error I find out a solution wich works fine and I can diplay the informations on the right site …
Thank you very much for your support! Now I´m very happy đ
-
AuthorPosts
- The topic ‘How to add a widget area directly after the header’ is closed to new replies.