ThemeShaper Forums » Thematic

javascript does not work in child theme functions.php

(6 posts)
  • Started 10 years ago by rhandthematic
  • Latest reply from helgatheviking
  • This topic is resolved
  1. I use this code to load a javascript to create tabbed boxes with DOM Tabs

    $theme_name= 'Thematic Child Theme';
    function domtab_link() {
        echo '<script type="text/javascript" scr="' . get_bloginfo('stylesheet_directory') . '/scripts/domtab.js"></script>' . "\n";
    add_action('wp_head', 'domtab_link');

    I use this code mentioned above in my child theme thematic/thematic-child/functions.php . It does load the javascript in the source code, but does not work. Any ideas why?

    Posted 10 years ago #
  2. Well, used the forum function and apparently I am supposed to use the WP enque and register script, which does make a lot of sense. And, for the action hook I need to use init instead of wp_head:

    function my_scripts() {
    wp_register_script('dom_tab', get_bloginfo('stylesheet_directory') . '/scripts/domtab.js');
    add_action('init', 'my_scripts');

    Like that is does register properly, not just show up in the source code.

    Posted 10 years ago #
  3. 11thinking

    Try this:

    function domtab_link() { ?>
        <script type="text/javascript" scr="<?php bloginfo('stylesheet_directory'); ?>/scripts/domtab.js"></script>
    <?php }
    add_action('wp_head', 'domtab_link');

    It's actually the same, but it may work?

    Posted 10 years ago #
  4. well you likely still need some kind of script that calls the function defined in your domtab.js on a particularly selector

    <script language="JavaScript">
    // What is $(document).ready ? See:
    jQuery(document).ready(function($) {
    Posted 10 years ago #
  5. 11thinking


    After I posted, the creator of this topic changed the topic to "resolved", so I guess it worked.

    Posted 10 years ago #
  6. @11thinking - lol. good to know.

    Posted 10 years ago #

RSS feed for this topic


You must log in to post.