Trying to fit a widget area output into content using add_filter
-
I’m trying to add a widget area to appear at the end of the content area on single posts, but inside the post. I’ve set up a function to filter the content and add a widget area.
I’m getting errors on the variable line where I’m declaring the widget group as a variable. Apparently my
<div class="in-content">
cannot start a variable because I’m gettingParse error: syntax error, unexpected '<' in ...
I’m trying to find out how I can get this widget code declared properly so that it can be a variable and get filtered in. Where would I find info on the correct way to syntax this? I’ve looked at other code examples for some hints, and even tried the PHP area of W3Schools, but I’m not seeing it.
Could someone point me to a correct place to find this info?
Thanks.
// 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; }
Note: I had the line
$sbadspace = <div class="in-content">
set originally as$sbadspace = ?><div class="in-content">
with a?>
to keep the PHP syntax going, but the errors said it was unexpected. So my code above has a missing?>
because that’s where I’m at.
- The topic ‘Trying to fit a widget area output into content using add_filter’ is closed to new replies.