• David Borrink

    (@davidborrink)


    In my posts, I’m using a Zemanta related posts plug-in. It hooks into my site using this:

    add_filter('the_content', 'zem_rp_add_related_posts_hook', 10);

    I want to put a widget area above it so I can put some of my own ads in every post after the content but before Zemanta.

    My code is this:

    // Register ad spot for inside lower content area
        register_sidebar( array(
                'name' => __( 'In-Content Space', 'tto' ),
                'id' => 'in-content-ad-space',
                'description' => __( 'IN-CONTENT AD SPACE. Puts content above the Zemanta area.', 'tto' ),
                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
                'after_widget' => '</aside>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
        ) );
    
    add_filter('the_content', 'sb_in_content_widget', 9 );
    function sb_in_content_widget () { ?>
          
                <div class="in-content">
                     <?php if ( is_active_sidebar( 'in-content-ad-space' ) ) : ?>
                           <?php dynamic_sidebar( 'in-content-ad-space' ); ?>
                     <?php endif; ?>
               </div><!-- .in-content-->
    }

    Note that I’m using a priority of 9 to put it before Zemanta.

    I created a text widget with sample text to try it. When I try it, my post content disappears with my Zemanta box. All that shows is my test widget, then the comments block.

    What am I missing here? Using add_filter should add my widget area into the content, not replace it. Zemanta uses add_filter to get in there without a problem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@alchymyth)

    Thread Starter David Borrink

    (@davidborrink)

    Okay, I see. I was replacing the content, not adding to it. Thanks. I see my mistake. Thanks for pointing me to the reason.

    Thread Starter David Borrink

    (@davidborrink)

    Okay, I’m trying this out and I’ve based this on the last example from the codex page noted two posts above here, but it’s not working. I’m getting the white screen of death with no message to tell me what line it’s failing on.

    What I’m trying now is to add the widget area into the function to filter the content by adding the widget area after the content. I’m testing on an internal setup without the Zemanta plug-in so there’s no additional function being added at this time. I’m just trying to get this widget to show up in the content for now.

    // Register ad spot for inside lower content area
        register_sidebar( array(
                'name' => __( 'In-Content Space', 'tto' ),
                'id' => 'in-content-ad-space',
                'description' => __( 'IN-CONTENT AD SPACE. Puts content above the Zemanta area.', 'tto' ),
                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
                'after_widget' => '</aside>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
        ) );
    
    add_filter( 'the_content', 'sb_in_content_widget' );
    function sb_in_content_widget () {
               if ( is_singular('post')) {
            $sbadspace = ?><div class="in-content">
                     			<?php if ( is_active_sidebar( 'in-content-ad-space' ) ) : ?>
                           		<?php dynamic_sidebar( 'in-content-ad-space' ); ?>
                     			<?php endif; ?>
               			</div><!-- .in-content-->
    				<?php 
           $content = $content . $sbadspace;
    		}
                endif;
        return $content;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Inserting a widget area in bottom of content area but before another plug-in’ is closed to new replies.