WordPress.org

Ready to get started?Download WordPress

Forums

Loading a script into post pages only (2 posts)

  1. Mr_Scientist
    Member
    Posted 3 years ago #

    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');
  2. SSchat
    Member
    Posted 2 years ago #

    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"...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags