Prioritizing wp enqueue scripts error
You got parentheses levels slightly wrong and that broke your callbacks. It should be: add_action( ‘wp_enqueue_scripts’, array( __CLASS__, ‘frontend_enqueues’ ), 1 );
You got parentheses levels slightly wrong and that broke your callbacks. It should be: add_action( ‘wp_enqueue_scripts’, array( __CLASS__, ‘frontend_enqueues’ ), 1 );
You don’t need to register it but in your own js file, replace the first $ to jQuery. jQuery is loaded in No Conflict Mode jQuery(document).ready(function($) { // Your code here. Use $ as normal. }); And if you use anonymous functions, do it like this (function($) { // Your code here. Use $ as … Read more
An action can be removed in time that pass since it is added to it is fired. So after is added, before is fired. You say the plugin has thiss code: add_action(‘wp_enqueue_scripts’, ‘poll_scripts’); function poll_scripts() { // code } But you don’t say if this code is inside a function hooked somewhere. If it is … Read more
You need to register/enqueue your admin scripts on admin_enqueue_scripts, not on wp_enqueue_scripts. wp_enqueue_scripts is a front end hook. It won’t run on the admin pages. Secondly, is_admin() just checks whether the page is an admin page, not whether the user is an administrator. To check whether the user is an administrator use: $current_user = wp_get_current_user(); … Read more
It is required, actually. There’s no real difference between themes and plugins as such. Neither of them should take actions on merely being loaded, they should use action hooks on functions to have things happen in the correct ordering.
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=”https://platform.twitter.com/widgets.js”; fjs.parentNode.insertBefore(js,fjs);} }(document,”script”,”twitter-wjs”); var options = { “url”: “/my-styles.css” }; CustomizeTwitterWidget(options); Then enqueue it at footer as the dependent of twitter-customize script which you already enqueued. function my_footer_enqueue() { wp_register_script( ‘twitter-customize’, get_template_directory_uri() . ‘/js/customize-twitter-1.1.min.js’, array(), ‘1.0’, true ); wp_enqueue_script( ‘twitter-customize’ ); wp_enqueue_script( … Read more
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.
There is a way, but it’s not recommended since there might be some other inline scripts attached to the enqueued scripts. You can hook to the wp_enqueue_scripts action and empty the global $wp_scripts as follows: add_action( ‘wp_enqueue_scripts’, ‘remove_all_scripts’, 1000 ); function remove_all_scripts() { global $wp_scripts; $wp_scripts->queue = array(); } You can then run a loop … Read more
You can use a prefix like ‘xyz-‘ (basically a namespace) for the handle if the script or stylesheet you use is unique to your theme / plugin. Owl Carousel is not, so just ‘owlcarousel’ is fine. You’d use a prefix if you didn’t want any chance another loaded plugin might be using the same name … Read more
Is there a way to determine if my current PHP file is within the plugins’ folder or within the themes’ folder Broadly you always have path to current file (__FILE__) so you can always examine it for where you are and compare with context. This might be good enough in custom site, but likely too … Read more