Add SideBar/Widgets Just Below the Post

Theory is simple – you just hook onto the the_content filter with a priority higher, then that of other plugin handlers:

add_filter('the_content', 'insert_my_sidebar', 9);

And then in insert_my_sidebar function you insert your sidebar.

But there is a caveat – actually not only user plugins, but also default filters have priority of 10. So by default there is no way to differentiate between them. You will have to implicitly unset default filters and re-set them with a priority higher then that of yours.

remove_filter( 'the_content', 'wptexturize'        );
remove_filter( 'the_content', 'convert_smilies'    );
remove_filter( 'the_content', 'convert_chars'      );
remove_filter( 'the_content', 'wpautop'            );
remove_filter( 'the_content', 'shortcode_unautop'  );
remove_filter( 'the_content', 'prepend_attachment' );

And then:

add_filter( 'the_content', 'wptexturize', 8        );
add_filter( 'the_content', 'convert_smilies', 8    );
add_filter( 'the_content', 'convert_chars', 8      );
add_filter( 'the_content', 'wpautop'  , 8          );
add_filter( 'the_content', 'shortcode_unautop', 8  );
add_filter( 'the_content', 'prepend_attachment', 8 );

And you obviously should do that in the_content filter with even higher priority, like 7 🙂

UPDATE:

Complete example:

add_filter( 'the_content', 'prepare_to_insert_my_sidebar', 7);

function prepare_to_insert_my_sidebar($content)
{
    remove_filter( 'the_content', 'wptexturize'        );
    remove_filter( 'the_content', 'convert_smilies'    );
    remove_filter( 'the_content', 'convert_chars'      );
    remove_filter( 'the_content', 'wpautop'            );
    remove_filter( 'the_content', 'shortcode_unautop'  );
    remove_filter( 'the_content', 'prepend_attachment' );

    add_filter( 'the_content', 'wptexturize', 8        );
    add_filter( 'the_content', 'convert_smilies', 8    );
    add_filter( 'the_content', 'convert_chars', 8      );
    add_filter( 'the_content', 'wpautop'  , 8          );
    add_filter( 'the_content', 'shortcode_unautop', 8  );
    add_filter( 'the_content', 'prepend_attachment', 8 );

    add_filter('the_content', 'insert_my_sidebar', 9);

    return $content;
}


function insert_my_sidebar($content)
{
    ob_start();
    dynamic_sidebar('name_of_your_sidebar');
    $content .= ob_get_clean();

    return $content;
}