• I’ve added a widget above the featured pages on our site using the php snippet provided but I can’t seem to make the same snippet work below the featured pages at the same time. This is what I’m using above the featured pages I’d like to make another one below. What do I need to change to make this work.

    add_filter( 'tc_default_widgets' , 'add_featured_page_widget' );
    function add_featured_page_widget( $defaults ) {
     $defaults['fp_widgets'] = array(
                        'name'                 => __( 'Before Featured Pages Widget' , 'customizr' ),
                        'description'          => __( 'Above the featured pages area on home' , 'customizr' )
     );
        return $defaults;
    }
    
    add_action('__before_fp' , 'display_my_fp_widget');
    function display_my_fp_widget() {
        dynamic_sidebar('fp_widgets');
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • since you can’t invoke the same function twice you need to tweak the original one a little bit:

    add_filter( 'tc_default_widgets' , 'add_widget_below_fp' );
    function add_widget_below_fp( $defaults ) {
     $defaults['fp_widgets'] = array(
                        'name'                 => __( 'After Featured Pages Widget' , 'customizr' ),
                        'description'          => __( 'Below the featured pages area on home' , 'customizr' )
     );
        return $defaults;
    }
    
    add_action('__after_fp' , 'display_my_fp_widget_below');
    function display_my_fp_widget_below() {
        dynamic_sidebar('fp_widgets');
    }

    Post a link to your site 😉

    Thread Starter RageATL

    (@rageatl)

    The widget still isn’t showing up. I knew I had to change something from the original but I couldn’t figure out what to change. I pasted it just as you put it and got nothing.

    http://www.ifsfreight.com

    ok, make a backup of your functions.php

    Delete the code you put in and try with this chunk of code here instead:

    /********************************************************/
     //  Add a widget area after FP section inside the main wrapper on Home page
    /********************************************************/
    add_filter( 'tc_default_widgets' , 'add_posts_loop_widget' );
    
    function add_posts_loop_widget( $default_widgets_area ) {
    
    	$default_widgets_area ['posts_loop_widgets'] = array(
    		'name' => __( 'Posts Loop Widget One' , 'customizr' ),
    		'description' => __( 'Below the featured pages area on home' , 'customizr' )
    	);
    
    	return $default_widgets_area;
    }
    
    add_action('__after_main_container' , 'display_my_posts_loop_widget', 10);
    
    function display_my_posts_loop_widget() {
    	// if ( is_home() || is_front_page() ) {
    	if ( is_front_page() ) {
    	  ?>
    	  <div class="row-fluid">
    	    <div class="span12"><?php dynamic_sidebar('posts_loop_widgets'); ?></div>
    	  </div>
    	  <?php
    	}
    }
    
    // Style all the posts_loop widgets so they take up the right space
    add_filter( 'posts_loop_class', 'display_my_posts_loop_widget_class');
    
    function add_post_loop_widget_class() {
    	return 'span12';
    }
    // from http://presscustomizr.com/snippet/adding-widget-area-home/
    
    /********************************************************/
     //  Add a widget areas after main content section inside the main wrapper on Home page
    /********************************************************/
    add_filter( 'tc_default_widgets' , 'add_featured_page_widget' );
    
    function add_featured_page_widget( $default_widgets_area ) {
    
    	$default_widgets_area ['fp_widgets'] = array(
    		'name' => __( 'Featured Pages Widget One' , 'customizr' ),
    		'description' => __( 'After main content area on home' , 'customizr' )
    	);
    
    	return $default_widgets_area;
    }
    
    add_action('__after_main_container' , 'display_my_fp_widget', 20);
    
    function display_my_fp_widget() {
    	// if ( is_home() || is_front_page() ) {
    	if ( is_front_page() ) {
    	  ?>
    	  <div class="row-fluid">
    	    <div class="span12"><?php dynamic_sidebar('fp_widgets'); ?></div>
    	  </div>
    	  <?php
    	}
    }

    It works for me, lemme know.
    If it works you just have to adapt the hooks to display it wherever you want.
    G.

    what kind of widget are you putting into the new widget areas?

    Thread Starter RageATL

    (@rageatl)

    Hey Giorgio25b I’ve been super busy and haven’t had a chance to try your code out but thank you for responding. I’m just trying to add areas underneath the featured pages to include more information about the company. I don’t really have to do it with a widget but it was the only option I’ve seen on the customizr site. I would actually prefer not to use a widget if you know another way. If I hard code HTML before the footer hook it includes it everywhere on the site.

    You can hard code HTML into a text widget and with the conditional logic I put in the code above you can select where to output the widget area:

    if ( is_home() || is_search() ) {
         //do something
    }

    like this you have more flexibility than hard-coding html into a php page

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Widget Below Featured Pages’ is closed to new replies.