New answers tagged

1

I had 2 things wrong: I unregistered wordpress's jquery without properly registering my own (I concatenated my scripts ) I didnt have wp_footer() in my theme. the wp_enqueue_media() function loads the scripts to the footer.


2

Use wp_enqueue_scripts instead on init. This will ensure you the template is already loaded. add_action('wp_enqueue_scripts', 'maps_scripts'); Or you try to check the template using get_page_template_slug() instead of is_page_template: $tmp = get_page_template_slug($post_id); // provide page/post ID if('page-about.php' == $tmp) { // enqueue scripts ...


2

The priority is related to other actions for the same hook. For example, if another plugin would implement add_action for wp_enqueue_scripts with a lower priority, they would have their scripts loaded in front of yours. You should check what scripts are inserted above yours and see if there is a css conflict.


2

WP loads jQuery in no conflict mode so shortcut $ is not available for jQuery to use .You should not use the $ variable for jQuery within WordPress. jQuery(function ($) { //code here }) or (function($){ //code here })(jQuery); There are so many Q&A which refers to the same conflict issue.Check this and this.


1

There is no good way of doing this. One way is to enumerate the already registered scripts, like this: function yourplugin_add_my_stylesheet() { global $wp_styles; if ( $wp_styles instanceof WP_Styles ) { // enumerate all current styles foreach( $wp_styles->queue as $handle ) { // use the $handle to see if ...


0

Provided you've confirmed that WP's native 'suggest' script is actually being rendered on the page properly (ie. you're using the correct template for home vs front-page), sometimes to avoid script conflicts on the page, you need to wrap your script in an anonymous function. So something like: <script> (function($) { ...


2

I you want the script be enqueued on page-index.php and page-contact-us.php, then you must check that that page templates are used but you are checking if they are not used. Chagne this: if ( !is_page_template('page-templates/page-index.php') && !is_page_template('page-templates/page-contact-us.php') ) { with: if ( ...


-1

You can simply use wp_enqueue_script or wp_enqueue_style in the widget method (function) in your custom Widget class and it will load the scripts only if the widget is active. See details and example here: https://wpshed.com/wordpress/load-scripts-styles-widget-active/



Top 50 recent answers are included