So I should probably mention up front that I'm developing a plugin so my url is 'mysite.com/plugin' (Just in case this is related to my issue.
So, In my main plugin file (myplugin.php) I have added the following:
$plugin_url = plugins_url('/my-plugin-directory/');
immediately followed by
wp_enqueue_style('wp_enqueue_scripts', $plugin_url . 'css/boxes.css');
Great, so far so good. The plugin url is properly concatenated and the script is added to the page and appears in the source as
<link rel='stylesheet' id='wp_enqueue_scripts-css' href='http://mysite.com/plugin/wp-content/plugins/my-plugin-directory/css/mystyle.css?ver=3.5.1' type='text/css' media='all' />
at this point I can even echo $plugin_url;
which returns:
http://mysite.com/plugin/wp-content/plugins/my-plugin-directory/
Directly below that I have written the following function:
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_enqueue_script('jquery');
wp_register_script('jquery_masonry', $plugin_url.'js/jquery.masonry.min.js', array('jquery'), '2.0.110526' );
wp_enqueue_script('jquery_masonry');
}
Should work right? It doesn't. Instead, in the source it looks like this:
<script type='text/javascript' src='http://georgespake.com/pluginjs/jquery.masonry.min.js?ver=2.0.110526'></script>
Boooo...
So for the time being, I just wrote it out:
/****Add jquery stuff to header****/
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_enqueue_script('jquery');
wp_register_script('jquery_masonry', $plugin_url . '/wp-content/plugins/my-plugin-directory/js/jquery.masonry.min.js', array('jquery'), '2.0.110526' );
wp_enqueue_script('jquery_masonry');
}
This feels sloppy though because this is the only place I have to do this. Everywhere else, the $plugin_url
seems to return the proper string. What am I missing here?