I am creating a plugin and I want to show all sub category list in the top of every category page. I had created a function and call "wp_list_categories" in that function. The problem is when I call that via

add_filter('the_content', 'myfunction');

List of all sub category is return successfully. Before every post and i just want to show it in top before first post.

And when call same function via

add_filter('wp_list_categories', 'myfunction');

Nothing return and show blank page

  • are you sure to do that with a plugin ? it's "presentation-side" so I recommand you to make this in the theme
    – mmm
    Aug 9, 2015 at 7:36

1 Answer 1


loop_start should be a good option. loop_start executes before the loop displays the first post


add_action( 'loop_start', function ( $q )
    if (    $q->is_main_query() // Do this only for the main query
         && $q->is_category() // Only target category pages
    ) {

        // Add your code here 

  • awesome bro sve my life i was searching it from 2 days. i am new wordpress user. Thank you Very very Much can you give a like to my question? i m unable to give you like\ Aug 9, 2015 at 10:07
  • Glad to hear it worked. Enjoy :-) Aug 9, 2015 at 10:10
  • This should also answer your other question which I have indicated as a duplicate to this one ;-) Aug 9, 2015 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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