Adding Javascript to a WP page
-
I’m trying to create a wordpress page that runs javascript.
I think I have followed the directions from the WordPress codes Using_Javascript page
This is what I have done:
1) I created a file called instant_icon_widget.js and uploaded it to my themes js folder (theme is ipinpro). This is the javascript code:[Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]
I had this code running on an HTML page previously, so I’m pretty sure the code itself is fine.
2) I added the code to the functions.php file of my theme which looks like this:
function instant_icon_widget() { wp_enqueue_script('instant_icon_widget', get_template_directory_uri() . '/js/instant_icon_widget.js', array(), null, true); } add_action('wp_enqueue_scripts', 'instant_icon_widget');
3) I created a page template called page_instant_icon_widget.php which looks like this:
[Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]
4) I set up a page in WordPress which references the template. Only thing on the page is the page title and then in the page attributes section _instant_icons is selected as the template.
What I see when I view this page is just the page header and title of the page (from the page template). Nothing else – not even the html that is in the javascript.
I’ve obviously done something wrong (and I’m hoping it’s just something silly I’ve missed).
Thanks,
Coleen
- The topic ‘Adding Javascript to a WP page’ is closed to new replies.