Don’t understand how to link Javascript files in WordPress

Please read this documentation https://developer.wordpress.org/reference/functions/wp_enqueue_script/ You need to set 5th parameter to true so the javascript is loaded in the footer. wp_enqueue_script( ‘tyc_scripts’, get_theme_file_uri(‘/js/tyc_scripts.js’), array(), false, true ); if the issue still persists please add your js code inside jquery document.ready()

Move specific javascript to the footer

It is generally not recommended to put move javascript files to the footer, especially WordPress dependencies. WordPress and plugins require and expect dependencies to be in the header and things can go awry if they aren’t. There are workarounds for this, but in many cases if you do move things to the footer and a … Read more

Javascript code for Category

Write this in your theme’s functions.php file function category_enqueue_script() { $cat_education_id = ‘xx’; // category id for “education” $cat_dog_id = ‘yy’; // category id for “dog” if ( is_category() && ( is_category( $cat_education_id ) || is_category( $cat_dog_id ) ) ) { wp_enqueue_script( ‘my-js’, ‘filename.js’, false ); } } add_action( ‘wp_enqueue_scripts’, ‘category_enqueue_script’ );

Move main menu to top of screen

This is a two step solution: Install plugin “Options for Twenty Seventeen” (Link) Add the following CSS to “Design” > “Customizer” > “Additional CSS” .navigation-top { position: fixed; bottom: auto; left: 0; right: 0; top: 0; width: 100%; } .custom-header { padding-top: 50px; }

Load php function with AJAX on modal window

You can’t directly use sendTrailer.php ,wordpress can’t find this custom page directly so you have to specify fully path of that page using get_template_directory() In your ajax function write url : ‘<?php echo get_template_directory(); ?>/sendTrailer.php’

Using Javascript Callback from plugin in a theme

Ok, I found out here how to procede. It was so simple I could not believe: 1) include in theme a custom script with a dependency on the favorite plugin. example: wp_enqueue_script(‘script’, get_stylesheet_directory_uri() . ‘/js/myscript.js’, ‘simple-favorite’, ‘1.0.0’, true); 2) in myscript.js just define again the function, and make it do something: function favorites_after_button_submit(favorites, post_id, site_id, … Read more