Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created and registered side bar in function.php and using it another place. It's working fine. Now I like to use it just below the post. I have installed some plugins -Bookmarks, related post...etc. They are also coming just below post. I want to show first the sidebar then the plugins.

If I put code just after

the_content(); 

It appears after plugins, but I have to show before plugins.

Let me know how to do.

share|improve this question
add comment

1 Answer 1

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;
}
share|improve this answer
    
make sure you return the $content in your insert_my_sidebar –  Bainternet Feb 2 '11 at 17:06
    
plz give me sample insert_my_sidebar bcoz it should return string, how can we get sidebar as string? –  Brij Feb 3 '11 at 7:42
    
dynamic_sidebar returns boolean true/false, not working. –  Brij Feb 3 '11 at 15:11
    
Hmm... right. But anyway... it is the function you actually need. I updated example. –  jayarjo Feb 3 '11 at 16:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.