Use js script from one plugin in another plugin

I have two plugins that work together (one is an add-on of sorts). In the “main” plugin, I have a js function in a file located like so: wp-plugins/main-plugin-name/js/main-js.js If my secondary plugin, I have another .js file located like so: wp-plugins/secondary-plugin-name/js/sec-js.js In this second plugin’s .js file, I want to use a function located … Read more

Help with enqueing scripts in footer after init action

In my functions.php, I have set a register_scripts() and load_scripts(), and hooked them to the ‘init’ action. I have registered all the scripts to be loaded in the footer, in order to optimize page load. Some of the scripts I’ve registered in register_scripts() are not enqueued in load_scripts() because I only want to load them … Read more

wp_register_script not loading as expected

I am loading scripts like this: //load scripts //wp_register_script( $handle, $src, $deps, $ver, $in_footer ); add_action(‘wp_enqueue_scripts’, ‘load_scripts’); function load_scripts() { if (!is_admin()) { wp_register_script(‘modernizr’, get_bloginfo(‘template_directory’) .’/scripts/modernizr-latest.js’,false); wp_enqueue_script(‘modernizr’); wp_enqueue_script(‘jquery’, true ); wp_register_script(‘cookie’,get_bloginfo(‘template_directory’) . ‘/scripts/cookie.js’, array(‘jquery’), ‘1.0’,true); wp_enqueue_script(‘cookie’); wp_register_script( ‘Gmaps’, ‘http://maps.google.com/maps/api/js?sensor=false’, true ); wp_enqueue_script (‘Gmaps’); wp_register_script(‘plugins’, get_bloginfo(‘template_directory’) .’/scripts/plugins.js’,true); wp_enqueue_script(‘plugins’); wp_register_script( ‘maps_scripts’, get_bloginfo(‘template_directory’) . ‘/scripts/maps.js’, array(‘Gmaps’), ‘1.0’, true … Read more

scripts not enqueueing

I have been beating my head against this for a couple of hours now and can’t seem to figure it out. I am trying to enqueue a script into my page with the following code in my functions.php. function my_slider_scripts() { $scriptsrc = get_stylesheet_directory_uri().’/js/jquery.nivo.slider.pack.js’; wp_register_script( ‘nivo-slider-pack’, $scriptsrc ); wp_enqueue_script(‘nivo-slider-pack’); } add_action( ‘wp-enqueue_scripts’, ‘my_slider_scripts’ ); I … Read more

Performance-wise, is it better to enqueue a (small) script on every page or test to see if it’s needed?

I’m using the FitVids.js script to make YouTube video embeds work with a responsive layout. The script is < 3kb, but only about half of my pages actually have YouTube embeds. In terms of total load-time for a page that doesn’t contain a YouTube video, is it more costly to do a strpos() on the … Read more

Register script/style: Is it possible to customize the version query string via plugin?

Expanding on the question in the title: I would like to find a way (via a plugin) to use timestamps for the JS and CSS file version query strings that are output with wp_register_style and wp_register_script. I know this can be easily modified in the calls themselves, and I do it this way currently: $style_mtime … Read more

Getting jquery to work with custom theme

I am trying to get some jQuery plugins to work with my custom theme. Up until now I was doing this: function my_scripts_method() { wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js’); wp_enqueue_script( ‘jquery’ ); } if (!is_admin()) add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); But I’ve read one shouldn’t deregister core bundled scripts and replace them with other versions. So I’ve … Read more

How to detect if a function has been fired on any page so scripts/styles can be loaded conditionally

I’m building a small gallery plugin and I’d like to only load scripts/styles onto the page IF the gallery has been loaded via the template tag. The template tag can take a post ID parameter when used to call a post’s gallery from wherever you need within the theme. I know how to do this … Read more

if file_exists not working with wp_enqueue_style

Inside a function I’m doing something like this: $optional_css_exists = get_template_directory_uri() . “/css/optional.css”; if ( file_exists($optional_css_exists) ) { wp_enqueue_style(‘options’, get_template_directory_uri() . ‘/css/optional.css’, ‘style’); } But for some reason it’s not being enqueued. When I echo out $optional_css_exists, I get the correct path of the file. If I remove the if statement, the file is enqueued. … Read more