WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add .JS files to Child Theme? (7 posts)

  1. thathurtabit
    Member
    Posted 3 years ago #

    I've been trying unsuccessfully for the last few hours to include .js files with my Child Theme.

    This seems like such a simple thing, but the only mention the Codex has is this:

    Other files
    In addition to style.css, functions.php, and to template files like index.php, and home.php, a child theme can use any type of file full-fledged themes use, as long as that file is properly linked. For example, a child theme can use icons and images that are linked from its stylesheet, JavaScript files linked from the top or bottom of pages, or extra PHP files called from its templates or from its functions.php file.

    Can anyone let me know how to include JS files in Child Themes?

    Thank you.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. thathurtabit
    Member
    Posted 3 years ago #

    Hi esmi,

    Thanks for your help.

    Those links seem to be more concerned with standard Theme development, as opposed to Child Theme development.

    How, for example, would you include a link to a .jpg or .gif? As the:

    <img src="<?php bloginfo(template_url); ?>/images/myimage.jpg />

    - tag only references the Parent theme, so, does this mean that I will have to write a PHP function in my functions.php file for every single call to a file (img, js, css, etc.) that is local only to my child theme?

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Those links seem to be more concerned with standard Theme development, as opposed to Child Theme development.

    There's no difference really. Simply replace references to <?php bloginfo(template_url); ?> with<?php bloginfo(stylesheet_url); ?>`

  5. thathurtabit
    Member
    Posted 3 years ago #

    It seems the above suggestion doesn't work, as using <?php bloginfo(stylesheet_url); ?> gets the url of the actual stylesheet.

    For example using <?php bloginfo(stylesheet_url); ?> would bring the following: http://www.mysite.com/wp-content/themes/mytheme/style.css

    - and not the desired Child Theme directory.

    I'm looking for a way to reference files inside of the child theme, but using your last suggestion would bring this:

    www.mysite.com/wp-content/themes/mytheme/style.css/js/myjavascript.js

    which obviously doesn't work as required. Any suggestions?

  6. esmi
    Forum Moderator
    Posted 3 years ago #

  7. thathurtabit
    Member
    Posted 3 years ago #

    Thanks esmi, that helped.

    For anyone else following this, I was looking for the correct Child theme bloginfo references explained here:

    http://codex.wordpress.org/Function_Reference/bloginfo

Topic Closed

This topic has been closed to new replies.

About this Topic