I know that wp_enqueue_script() inserts Javascript files into the WordPress header in the appropriate place.

However, I want to include my Javascript in all single posts, ignoring the WordPress home or blog page.
Is that possible at all?

I tried this:

function my_scripts_method() {
    if ( is_single() ) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
        wp_enqueue_script( 'jquery' );
add_action('wp_enqueue_scripts', 'my_scripts_method');

But it's not working...

1 Answer 1


if you want it on all single posts as well as pages & custom post types, use is_singular() instead of is_single()

& just in case you're using it on the template, this code goes in functions.php


write this code just above your wp_head() function in header.php

global $wp_scripts;

This will display on the site all the info related to scripts registered in wordpress to be displayed. Read it & then see what scripts you want to display & what scripts are to be removed with wp_dequeue_script

To determine which page you are removing scripts from, you may look for various Conditional Tags

  • My Wordpress Home Page is too heavy with jquery, javascript bla bla. i'm trying to remove javascript who not necessary on home page. so i want to implement on my wordpress template. Please let me know, some trick to filter javasript on wordpress home page. Oct 19, 2012 at 14:52
  • All these javascript come form wordpress plugins Oct 19, 2012 at 14:53
  • This would have to be done on a plugin-by-plugin basis then as they most likely would all have unique script enqueue names. Also, you may risk having JavaScript errors popup on your home page if you just disable the scripts without disabling the plugins. Oct 19, 2012 at 15:43
  • so how i implement on plugin? i tested is_single() its not working Oct 19, 2012 at 16:48
  • 1
    Unfortunately not all plugins follow the rules when it comes to enqueueing scripts. There's a very good chance that between plugins and themes you'll have at least one instance where something is directly echoing a call for script inclusion. Oct 19, 2012 at 18:57

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.