• Resolved ArnoAnou

    (@arnoanou)


    Since we don’t use a sidebar I’d love to add some additional widget areas to the site. I downloaded the child theme and added the following code to the functions.php. Is it correct? Next step would be to implement these areas where they are supposed to be, would you (or any forum user here?) help me with this?

    if ( ! function_exists( ( 'ct_startup_blog_register_widget_areas' ) ) ) {
    	function ct_startup_blog_register_widget_areas() {
    
    		register_sidebar( array(
    			'name'          => 'Custom Before Content',
    			'id'            => 'custom-before-content',
    			'description'   => 'Widgets in this area will be shown before main content',
    			'before_widget' => '<section class="custom-before-content">',
    			'after_widget'  => '</section>',
    			'before_title'  => '<h2 class="widget-title">',
    			'after_title'   => '</h2>'
    		) );
    		register_sidebar( array(
    			'name'          => 'Custom After Content',
    			'id'            => 'custom-after-content',
    			'description'   => 'Widgets in this area will be shown after main content.',
    			'before_widget' => '<section class="custom-after-content">',
    			'after_widget'  => '</section>',
    			'before_title'  => '<h2 class="widget-title">',
    			'after_title'   => '</h2>'
    		) );
    		register_sidebar( array(
    			'name'          => 'Custom Footer',
    			'id'            => 'custom-footer',
    			'description'   => 'Widgets in this area will be shown in the footer.',
    			'before_widget' => '<section class="custom-footer">',
    			'after_widget'  => '</section>',
    			'before_title'  => '<h2 class="widget-title">',
    			'after_title'   => '</h2>'
    		) );
    	}
    }
    add_action( 'widgets_init', 'ct_startup_blog_register_widget_areas' );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Ben Sibley

    (@bensibley)

    I would recommend creating a new function rather than overriding the widget area function in Startup Blog. There’s no harm in having the After Post/Page Content widget areas and Primary Sidebar widget area available even if you don’t use them.

    Something like this will work well:

    function my_custom_register_widget_areas() {
    	register_sidebar( array(
    		'name'          => 'Footer',
    		'id'            => 'footer',
    		'description'   => 'Example description',
    		'before_widget' => '<section id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</section>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>'
    	) );
    }
    add_action( 'widgets_init', 'my_custom_register_widget_areas' );

    In Startup Blog, look at the sidebar-after-post-content.php file as an example for outputting a widget area. Then in line 22 of content.php, you can see how get_sidebar() is used to add the sidebar after the post content.

    Thread Starter ArnoAnou

    (@arnoanou)

    So, I hesitated to do this because I expected a whole lot of difficulties, but I finally did it and it worked like a charm. Thank you Ben for your help. I never edited php without any problems before and I just did. Wow!

    Maybe you want to have a look at it? There’s a before-main-content widget containing the newsletter form. It’s just shown on the blog page (thanks to a plugin) to not be to pushy and because it doesn’t work with the hero-image-template of the posts and pages (just looks weird between title image and article). There’s a after-main-content widget between content and footer containing the tag cloud, it is full-width on the hero-image posts and pages and I didn’t figure out how to change it without changing in on the front page, but we kinda like it. Plus there’s a footer widget containing a search bar.

    We wanted to do this because of the full-width-two-column layout we chose for the blog page and the hero-image templates without sidebar we chose for articles and pages. Because of this we had no widget areas left on the blog page, and just “inline” widget areas for posts and pages. Which for us weren’t good places for either of the widgets I mentioned. (I’m mentioning this because that maaaaaaay be thoughts other users might have too.) I’m so happy it works and that it looks fine. Thanks Ben!

    Theme Author Ben Sibley

    (@bensibley)

    Thanks for the detailed feedback. I’m glad that code worked well for you! I will have to consider some additional widget areas for situations like this. Maybe one after the first post on the blog.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Additional widget areas’ is closed to new replies.