- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Difficulty with linking JQuery and locating an image in WP Parent theme mobile
Here’s the link to the site: http://hajzer.info/
when you shrink to mobile the proper image doesn’t show. as well as jQuery does not work… i also can’t LOAD my javascript file , even if i put it in the head of the header.php file in a script tag.
This is the correct URL:
http://hajzer.info/wp-content/themes/THE_Theme/functions.js
But you should be registering that script and declaring jQuery as dependency.
function my_styles_scripts()
{
// Load Default Stylesheet
wp_enqueue_style( 'style', get_stylesheet_uri(), array(), '1' );
// Load JavaScript
wp_enqueue_script( 'my-functions', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '1', true );
}
add_action( 'wp_enqueue_scripts', 'my_styles_scripts' );
Put this in your functions.php
file. You no longer have to call jQuery or your functions.js
file from your templates.
But make sure your template has
<?php wp_head(); ?>
and <?php wp_footer(); ?>
I like to place wp_head
right before closing head tag </head>
and wp_footer
right before closing body tag </body>
.
When working with WordPress whenever you find your self hacking too much, there’s most likely a action hook provided by WP core that you can “hook” into, officially known as: add_action('name_of_the_hook', 'function_that_runs')
.
What the above function does is runs two functions provided by WP core wp_enqueue_style()
ref and wp_enqueue_script
ref. These functions can be used on their own, if you want. You can also write more complex logic that excludes certain files from loading on certain pages.
The hook is wp_enqueue_scripts which is a function used to output both style and a script. ref.
Hope that helps.