Tagged: 

Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #80405
    cytorath18
    Participant

    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.

    #80425
    Pratik
    Participant

    Hi @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.

    #80474
    cytorath18
    Participant

    I 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.

    #80495
    Pratik
    Participant

    Hi @cytorath18,
    Can you post your site url so i can check it?

    #80539
    cytorath18
    Participant

    I’m editing my site offline via Bitnami. I’ll see if I can maybe get it put up temporarily at a free hosting site.

    #80654
    cytorath18
    Participant

    I’ve uploaded a copy of my site so far to this link. Let me know if you need any further info.

    http://boldpenguindesign.x10host.com/

    #80669
    Pratik
    Participant

    Can 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);

    #80779
    cytorath18
    Participant

    Your second suggestion worked like a charm. Thanks! 😀

    #80797
    Pratik
    Participant

    Hi 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

    #81198
    NickBallDesign
    Participant

    This 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.

    #81234
    Pratik
    Participant

    hi @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.

    #93567
    marie21
    Participant

    Hi 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?

    #93573
    marie21
    Participant

    Update: 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?

    #93607
    Pratik
    Participant

    @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,
    Pratik

    #93637
    marie21
    Participant

    Hello 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

    #93655
    marie21
    Participant

    Update: 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

    #93670
    Pratik
    Participant

    @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,
    Pratik

    #93697
    marie21
    Participant

    Hi 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 🙂

Viewing 18 posts - 1 through 18 (of 18 total)
  • The topic ‘How to add a widget area directly after the header’ is closed to new replies.