• Resolved maxatlanta

    (@maxatlanta)


    Hello,
    I need to add a new js script to my child theme. Since it needs to be located in the <head> and used for a specific page, i was wondering if somebody could show what kind of action I need to add in my functions file. Everything else is in the right place (js locations, classes, html)
    I think it should be something like this, but it needs to point to a specific page ID, but I am not a programmer:

    add_action('wp_head','my_equalHeight',1,20);
     function my_equalHeight() {
    	?>
     (<script src="equalHeight.min.js"></script>)
     <?php
    }

    Thank you and compliments for a very versatile theme, Massimo

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author presscustomizr

    (@nikeo)

    Hi @maxatlanta, thanks for your comment.

    You’re almost there! You just have to add a php condition to insert or not this script tag.
    This could be done with the built-in WordPress conditional tags.
    In you case, is_page() would be perfect.

    add_action('wp_head','my_equalHeight',1,20);
     function my_equalHeight() {
        if (! is_page( 10 ) )
          return;//<= this simply says : if the requested page is not the one with id equal 10, then do nothing. Note that you can also use the page title or the page slug with is_page(), check the codex for more info.
    	?>
     (<script src="equalHeight.min.js"></script>)
     <?php
    }
    Thread Starter maxatlanta

    (@maxatlanta)

    Hi Nikeo,

    thanks for the super fast clarification!
    I will send you a link when we go live so you can see how your theme was used

    Merci beaucoup, Nico

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘adding script to section’ is closed to new replies.