Support » Fixing WordPress » add call to js file in child functions.php

  • Resolved almcr

    (@almcr)


    I have created a copy of the theme shipyard into a theme I call curling55 and have now created a child theme of curling55 as well, I want to make any further theme changes in the child theme.

    I want to call in the js file respond.src.js to handle media queries in IE8, but this must be called after the style sheet is loaded. The code in the parent theme is:

    // Enqueues scripts and styles for front-end
    function curling55_scripts() {
    if (!is_admin()) {
    wp_enqueue_style( ‘style’, get_stylesheet_uri() );
    wp_enqueue_script( ‘nav’, get_template_directory_uri() . ‘/js/nav.js’, array( ‘jquery’ ) );
    }
    if ( is_singular() && comments_open() && get_option( ‘thread_comments’ ) )
    wp_enqueue_script( ‘comment-reply’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘curling55_scripts’ );

    If I code up functions.php in the child theme like this:

    <?php
    /***
    * Add call to respond.src.js so IE8 can process media queries
    * (must follow call to style.css)
    *
    */
    // Enqueue scripts and styles
    function curling55child_scripts() {
    wp_enqueue_script( ‘respond’, get_stylesheet_directory_uri() . ‘/js/respond.src.js’, array( ‘jquery’ ) );
    }
    add_action( ‘wp_enqueue_scripts’, ‘curling55child_scripts’, 20 );
    ?>

    I get this error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/s/u/n/sunflowerbaker/html/wp/wp-content/themes/curling55-child/functions.php:12) in /home/content/s/u/n/sunflowerbaker/html/wp/wp-includes/pluggable.php on line 896

    How do I code the functions.php in the child theme to do this and not give me an error?

    Al

Viewing 3 replies - 1 through 3 (of 3 total)
  • Please wrap your code in barticks or otherwise follow forum rules to post code. Please review and do so.

    http://codex.wordpress.org/Forum_Welcome#Posting_Code

    You may have time to edit your post.

    Also, review the order of .js and .css output as set in ‘<head>’ or otherwise within site content.

    Thread Starter almcr

    (@almcr)

    OK thanks about the code.

    looks like it is displaying correctly, so wont change it this time.

    my question remains – how do load in a new js file in the child functions.php code with the condition that it loads after the style sheet is loaded??

    can this be done within the enqueue_scripts code? or do I just add code to load the js file after wp_head in header.php??

    this type of problem outlines why I think handling functions in the child functions.php is the most difficult part of child themes.

    Al

    Thread Starter almcr

    (@almcr)

    took the ‘?>’ off the child functions.php file and now it seems to be working.

    strange?

    is this one of the quirks about the theme functions.php file?

    Al

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add call to js file in child functions.php’ is closed to new replies.