I am building a plugin that is only useful and should only run on pages where posts are featured.

Is there a way to only run the plugin on pages that display posts?

| improve this question | | | | |
  • there are several ways to limit where/when a plugin does various things, depending on what exactly your plugin does- loading of styles, loading of scripts, modification of queries, etc., you'll have to provide more details as to what your plugin does for an actual, practical answer. – Milo Jan 8 '14 at 3:13

No, the plugin is loaded long before WordPress has figured out if it should display a single post.

But you can restrict the code of the plugin to do something only then.


add_action( 'template_redirect', function() {

    if ( ! is_single() )

    // initialize plugin code here.
| improve this answer | | | | |

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.