0

Basically, I want my jQuery plugin to run only on article pages, that is, not on the home page, or other pages. Right now, I am doing this in the following way:

if ( is_single() ) {
    launchPlugin();
}

In other words, if the is_single() function returns true, I start my plugin. Am I doing it right? Is it universally acceptable for all WordPress blogs?

1 Answer 1

1

Yes, this should be correct. Is_single returns true on single post pages, both normal and custom post types. Note that if you also want to run your script on pages, you will need is_singular. The latter allows you to specify which post types the script should be included with, so it gives you more flexibility.

And yes, this should work for all WordPress blogs, though you should always wonder what happens if some other plugin interferes with yours. There's no 100% guarantee that it will always work.

2
  • When you use is_singular it is not only true for posts and pages. It is true for is_attachment() also.
    – Ranuka
    Nov 16, 2016 at 11:25
  • @Ranuka. That is correct. Depending on whether OP wants to run his script on attachment posts as well, he can specify it in the parameters of is_singular.
    – cjbj
    Nov 16, 2016 at 11:36

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.