Support » Plugins and Hacks » Loading a script into post pages only

  • Mr_Scientist

    (@mr_scientist)


    I’m trying to include a script called Ketchup into post pages only and have written the following code in the functions php. I cannot work out why this if statement isn’t working. When the if statement is taken out and only the ‘enqueue’ part left in it loads, but into all pages.

    function call_ketchup() {
    	if (is_single()) {
    		wp_enqueue_script('ketchup', get_bloginfo('template_url') ."/scripts/jquery.ketchup.all.min.js", array('jquery'), '1.0');
    }
    add_action('init', 'call_ketchup');
Viewing 1 replies (of 1 total)
  • function call_ketchup() {
    	if (is_single()) {
    		wp_enqueue_script('ketchup', get_bloginfo('template_url') ."/scripts/jquery.ketchup.all.min.js", array('jquery'), '1.0');
    }
    add_action('init', 'call_ketchup');

    is missing the “}”?

    maybe the action “init” is to early.
    try another action like “wp_head”…

Viewing 1 replies (of 1 total)
  • The topic ‘Loading a script into post pages only’ is closed to new replies.