Multisite plugin development and wp_enqueue_script

I have a plugin I’m developing. It works fine on a single site version of WordPress. It installs on a multisite version of WordPress, it appears to work on the admin pages, but when the plugin attempts to add javascript and css, it’s not added. The display portion of the code is as follows… add_action(‘init’, … Read more

How resource intensive is wp_register_script()?

I’m trying to use the has_shortcode() function to only load certain scripts when there is a shortcode in the post’s content, with this code: wp_register_script( ‘shortcode-js-file’ , FILE_URI, array( ‘jquery’), ”, true ); if(isset($post->post_content) && has_shortcode($post->post_content, ‘shortcode_name’)) { wp_enqueue_script( ‘shortcode-js-file’); } So in the above code, I’m registering the script on all pages, whether there … Read more

Is it safe to enqueue a font style without putting http or https?

I have seen a few WordPress sites and tutorials enqueuing fonts like this. Does this work with http and https sites? Is it safe to do this? I see these exact URL’s in the source code when testing this function on an http site. add_action(‘wp_enqueue_scripts’, ‘theme_external_styles’); function theme_external_styles(){ wp_enqueue_style( ‘main_css’, ‘//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css’ ); wp_enqueue_style( ‘roboto’, ‘//fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,500italic,400italic,300italic,100italic,700italic’ … Read more

Bootstrap js refuses to load

I’ve used a small javascript file to create an off canvas push navbar. I loaded the file as described in the Wordpres Codex: function sidebar () { wp_enqueue_script(‘theme-js’, get_stylesheet_directory_uri() . ‘/js/nav-sidebar.js’,array( ‘jquery’ ),$version,true ); } add_action(‘wp_enqueue_scripts’, ‘sidebar’); However, it seems that the only js that is loaded is the nav-sidebar and the bootstrap.js refuses to … Read more

How to properly add Bootstrap and JQuery Javascripts?

I am developing my WordPress theme using Material Bootstrap Design (MDB), a Material variant that uses Bootstrap 4 plus its own code. It calls for using the following scripts… <!– JQuery –> <script type=”text/javascript” src=”https://wordpress.stackexchange.com/wp-content/themes/blankslate/mdb/js/jquery-2.2.3.min.js”></script> <!– Bootstrap tooltips –> <script type=”text/javascript” src=”/wp-content/themes/blankslate/mdb/js/tether.min.js”></script> <!– Bootstrap core JavaScript –> <script type=”text/javascript” src=”/wp-content/themes/blankslate/mdb/js/bootstrap.min.js”></script> <!– MDB core JavaScript –> … Read more

wp_enqueue_script fails to include in footer

In my WordPress plugin I try to include two scripts in the page footer, like so: function my_interface_enqueues() { wp_enqueue_script( ‘require-js’, plugin_dir_url( __FILE__ ) . ‘js/libs/requirejs/require.js’, array(), false, true ); wp_enqueue_script( ‘main-js’, plugin_dir_url( __FILE__ ) . ‘js/main.js’, array(), false, true ); } Yet when I check the rendered page, the scripts are inside the <head>, … Read more

How do I add a javascript file to all admin pages via a plugin?

Context: For logged in users, I’m appending a query string to the url so that it will bypass Cloudflare’s cache. So, example.com becomes example.com/?nocache=y, for example. I accomplished this pretty easily with the following code: function tbcloudflare_query_arg() { if(is_user_logged_in()){ wp_enqueue_script( ‘tbcloudflare_check_query’, plugin_dir_url( __FILE__ ) . ‘js/tbcloudflare.js’, array(‘jquery’), ‘1.0’ ); } } add_action(‘wp_enqueue_scripts’, ‘tbcloudflare_query_arg’); I can … Read more