ThemeShaper Forums » Thematic

javascript does not work in child theme functions.php

(6 posts)
  • Started 8 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

    <?php
    $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 8 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:

    <?php
    function my_scripts() {
    wp_register_script('dom_tab', get_bloginfo('stylesheet_directory') . '/scripts/domtab.js');
    wp_enqueue_script('dom_tab');
    }
    add_action('init', 'my_scripts');
    ?>

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

    Posted 8 years ago #
  3. 11thinking
    Member

    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 8 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: http://flowplayer.org/tools/documentation/basics.html#document_ready
    jQuery.noConflict();
    
    jQuery(document).ready(function($) {
    
    $(#selector).dosomething();
    
    });
    </script>
    Posted 8 years ago #
  5. 11thinking
    Member

    @helgatheviking

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

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

    Posted 8 years ago #

RSS feed for this topic

Reply

You must log in to post.