1

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?

1
  • 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
    Commented Jan 8, 2014 at 3:13

1 Answer 1

2

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.

Example:

add_action( 'template_redirect', function() {

    if ( ! is_single() )
        return;

    // initialize plugin code here.
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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