Tag Info

New answers tagged

0

First, create a static js file with those inline codes.. !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0]; if(!d.getElementById(id)){js=d.createElement(s);js.id=id; js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js,fjs);} }(document,"script","twitter-wjs"); var options = { "url": "/my-styles.css" }; ...


0

Following code can be used to add script in footer BUT I should mention here that this is not the recommended way in WordPress. add_action( 'wp_footer', 'custom_footer_script', 100 ); function custom_footer_script(){ ?> <script> // your script </script> <?php } Alternative: Have to tried creating separate script file adding ...


0

add_action( 'wp_enqueue_scripts', 'load_scripts '); function load_scripts() { if ( !is_admin() ) { wp_enqueue_script( 'jquery' ); wp_register_script( 'twitter-customize', get_bloginfo( 'template_directory' ) .'/js/customize-twitter-1.1.min.js', array( 'jquery' ), '1.0', true ); wp_enqueue_script( 'twitter-customize' ); } ...


2

You don't have to provide source or dependencies, they're already registered by the script loader with those values, you just need to enqueue the proper handle.


1

You have a basic mistake in your code. The following code if ( !is_page('my-page') ) { means that if you are not on that page, deregister the scripts. Have a look at the php operators ! -> Not !$x True if $x is not true Also, why not exclude this specific page when you initially enqueue these scripts, something like add_action( ...


1

I'd probably try only enqueueing those scripts on specific pages, rather than enqueuing and then dequeuing them: function wpse158453_enqueue_scripts() { if(!is_page('my-page')) { wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' ); wp_enqueue_script( 'jquery-ui', ...


0

The better way I've found is using wp_localize_script(), as @scribu suggested. Usually, I decided to use in-line Javascript because I needed to provide some PHP variables to my script. This can be solved with wp_localize_script(). I'll provide an example: You have an array $aFoo with some options and need to pass it to a script. $aFoo = array( 'option1' ...


2

Use in_array(): if ( in_array( $hook, [ 'user-edit.php', 'profile.php' ] ) ) // do something Or wait for the action personal_options, and enqueue the script for the footer. This action is fired in both cases. See this old example.


2

Try to remove this from footer.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> And One tip: Use wp_enqueue_script to load all JS on your web page.


6

You're mixing up the singular wp_enqueue_script, which adds a script, with the plural wp_enqueue_scripts which is an action and a function that triggers that action. I think you want function theme_scripts() { wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/menu-fix.js', array('jquery'), '1.0', true); } ...


1

The dependencies are case-sensitive - you need array( 'jquery' ) (no uppercase Q).


1

OK, you have two problems here. Firstly, you are enqueueing your style with wp_enqueue_script(), which is meant to be used by scripts. You should be using wp_enqueue_style Secondly, you need to understand what functions are loaded when. Plugins are loaded first, child themes second and parent themes last. So you styles gets loaded first, and then the ...


0

I solved my problem after a long time struggling, that's why I think I should list some tips for someone with a problem like this: If you change your javascript file, use ctrl+f5 to force reload the page and the resources. The caching almost got me crazy as I changed the file and the changes didn't take place. Use your browser's network analisys tool. In ...


2

My guess would be that you are remove the action before it is actually being added in the parent theme. The parent's theme functions.php file gets loaded after the child one so it looks like your removing something that is not there yet. The 3rd parameter in remove_action() is the priority. Try playing around with that number - the default is 10 - to see ...



Top 50 recent answers are included