- Should a plugin be able to add a widget area above the_content? (Without requiring template/theme changes.)
- What would be the best way to do this? Doubts: widgets typically echo output to the screen; the_content filter examples always return $content. The code below does something but seems flawed: testing indicated that shortcodes were not being parsed so I added do_shortcode.
function insert_above_content_widget($content) {
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Above Content') ) : endif;
echo do_shortcode($content);
}
The code below does something but seems flawed: testing indicated that shortcodes were not being parsed so I added do_shortcode.
add_filter( 'the_content', 'insert_above_content_widget' );
function insert_above_content_widget($content) {
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Above Content') ) :
endif;
echo do_shortcode($content);
}
add_filter( 'the_content', 'insert_above_content_widget' );
Seems like it would be a useful thing to be able to do but this approach doesn't feel right somehow. Anyone see any problems?