Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Paul Yorde
Paul Yorde
10,497 Points

enqueue script in wordpress plugin for specific hook

When custom php function is called, need to register and enqueue script from within that called function. Then the whole thing gets added to wp_footer hook. the echoed div in code below shows up in the developer tool, but the script is not showing or even giving any errors, i.e.- if this were an issue with the file path, then there would be resource error, yes?

The code:

if(get_option('show_content')) { 

    function add_time() {
        echo '<div id="txt">' . '</div>';
        // add script tut pro word plugin dev ch12.3
        function py_enqueue_script () {

            wp_register_script( 'timescript', plugin_url('../time.js', __FILE__));
            wp_enqueue_script( 'timescript'); 

        } // end py_enqueue_script
        add_action('wp_enqueue_scripts', py_enqueue_script);

    } // end show add_time

    add_action("wp_footer",add_time);

} // end if ```