Execute a plugin only on post pages

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?

Related posts

1 comment

  1. 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.
    });
    

Comments are closed.