WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A few basic questions to accelerate my wordpress plugin development start. I'd like to develop a wordpress plugin that adds some javascript and css to a specific page. What filters or actions should be used? How to restrict execution of a plugin to a single (known) page? How can a plugin add some content to a page?

share|improve this question
up vote 2 down vote accepted

WordPress has a built-in function called wp_enqueue_script() which will allow a certain piece of JavaScript to be included in a page. If you'd just like to see that script on a particular page, you can conditionally call it from the theme file. For example:

<?php if (is_page('home')) {
    wp_register_script('custom_script', get_template_directory_uri() . 
} ?>

You can do something similar with wp_register_style() and wp_enqueue_style() to include the CSS as well.

share|improve this answer
Additionally, you can modify actions and filters within the if statement, that way the hooks and filters are only modified for that page as well. – mor7ifer Jan 30 '12 at 17:06

Take a look at Page Specific CSS/JS plugin source code -- This simple plugin allows you include a separate stylesheet and/or javascript file for any page on your site.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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