Skip to main content
formatting
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459
  1. Should a plugin be able to add a widget area above the_content? (Without requiring template/theme changes.)
  2. 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?

  1. Should a plugin be able to add a widget area above the_content? (Without requiring template/theme changes.)
  2. 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);

}

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?

  1. Should a plugin be able to add a widget area above the_content? (Without requiring template/theme changes.)
  2. 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);

}

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?

Source Link
Jon
  • 103
  • 8

Can / should a widget plugin define its own Widget Area?

  1. Should a plugin be able to add a widget area above the_content? (Without requiring template/theme changes.)
  2. 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);

}

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?