Thread Starter
repl35
(@repl35)
The website I am requesting is columbussurgical.com .
maybe you could try something like this with jquery?
$(document).ready(function(){
$( "a.close-map" ).trigger( "click" );
});
Thread Starter
repl35
(@repl35)
I’ve tried, and doesn’t work…. Would I need to put anything in the header to reference the jquery library? I thought it would already be in there.
Nope, unless a theme enqueues jQuery for its own purposes, the libraries are not loaded on front end pages by default. The proper way to load JS and jQuery script is with wp_enqueue_script()
https://developer.ww.wp.xz.cn/reference/functions/wp_enqueue_script/
At the very least you need
function my_scripts_method() {
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
You can get away with placing little scripts like Alphonso suggested inside <script> tags on the page itself. Because the WP jQuery library runs in noConflict mode, Alphonso’s first line should be
jQuery( document ).ready( function( $ ){
ups, yes. I missed that!
bcworkz is right.
you could check your bowser console for any javascript errors too
Thread Starter
repl35
(@repl35)
Okay. Would the script that bcworkz suggested go in the header.php? Sounds like it would? I’ll try looking at javascript errors.
One would think so, but no. It actually belongs in functions.php. By adding an action, when the head section is output, the ‘wp_enqueue_scripts’ action fires and any enqueued scripts are loaded in the proper order determined by an optional dependency argument of wp_enqueue_script().
If you had more complex scripts, they should be contained in a separate .js file that is also enqueued and ‘jquery’ specified as a dependency to ensure it’s loaded after the jQuery library. By using inline script, you bypass this mechanism, so you need to ensure your script occurs after jQuery is loaded. Anywhere in the body section will be fine. I suggest placing inline script on whatever template is causing the map container to be output.