Like Quicoto, I am also just adding scripts the usual way that I know of, so this is really something new to me and much more helpful. Thanks for sharing this. Will be bookmarking this.
There’s also plugins_url(), includes_url(), admin_url(), and site_url(). These have been around since WP 2.6.
WP 3.0 adds a bunch of new ones, like home_url and network_home_url and so forth. All these work basically the same way.
The reason you should use these is that they take path changes and https and other things into account and such. They’re also shorter and less likely to break in the future than defines and such are.
Those functions don’t seem to be covered in the Codex, at least Google and the Codex search don’t seem to have them listed. This was the closest I could find, and it’s recommending the constants (WP_…_URL).
Thanks for publishing this article! It mirrors one that I published a while back on my whypad blog, but this will definitely hit a bigger audience. This script inclusion problem is the single biggest problem I see with people who use my plugin. Most of my forum posts are people saying that uploading images doesn’t work, and 95% of the time it is due to either the theme or some other plugin loading jQuery without using the enqueue function. I’ve seen jQuery being loaded 3 or 4 times on the same page while helping folks.
You might also mention the wp_head() and wp_footer() sins of omission as well. Those seem to be getting better, but I still get a fair number of people coming by with a missing wp_footer, which is where Thickbox gets added.
After searching for nearly 30 mins to get the syntax so i could understand what the true and false were being used for this article is the clearest and easiest to understand. Many Thanks it’s helped me to load jquery and jquery-ui.min from google and place it in the footer.
Great work thanks for sharing,
Ian
Interesing. I was not using this function I was just adding the scripts in the normal way.
Regards
It definitely helps with script conflicts. I think you’ll find it useful.
Like Quicoto, I am also just adding scripts the usual way that I know of, so this is really something new to me and much more helpful. Thanks for sharing this. Will be bookmarking this.
Why don’t you use WP_PLUGINS_URL instead of WP_CONTENT_URL . ‘plugins ?
Habit – I do in some of my code though.
Use of those WP_*_URL constants is actually not recommended. Instead, you should use the functions designed for this purpose.
Will produce: http://example.com/blog/wp-content/whatever
There’s also plugins_url(), includes_url(), admin_url(), and site_url(). These have been around since WP 2.6.
WP 3.0 adds a bunch of new ones, like home_url and network_home_url and so forth. All these work basically the same way.
The reason you should use these is that they take path changes and https and other things into account and such. They’re also shorter and less likely to break in the future than defines and such are.
Okay, so my PHP got nixed. That should have read:
echo content_url(‘/whatever’);
Will produce: http://example.com/blog/wp-content/whatever
Thanks. That’s good info.
Otto,
Those functions don’t seem to be covered in the Codex, at least Google and the Codex search don’t seem to have them listed. This was the closest I could find, and it’s recommending the constants (WP_…_URL).
http://codex.wordpress.org/Det.....irectories
Any ideas where the directory/url functions might be documented?
Thanks,
Byron
Otto,
Thanks for this tip! I’d become quite fond of WP_PLUGIN_DIR and WP_PLUGIN_URL. This is good to know. Will start revamping…
Thanks for publishing this article! It mirrors one that I published a while back on my whypad blog, but this will definitely hit a bigger audience. This script inclusion problem is the single biggest problem I see with people who use my plugin. Most of my forum posts are people saying that uploading images doesn’t work, and 95% of the time it is due to either the theme or some other plugin loading jQuery without using the enqueue function. I’ve seen jQuery being loaded 3 or 4 times on the same page while helping folks.
So, THANK YOU, THANK YOU, THANK YOU!!!!
@Byron,
Wow, never seen it that bad.
Another “sin” I didn’t mention is people who still use the “onload” event.
@Ronald,
You might also mention the wp_head() and wp_footer() sins of omission as well. Those seem to be getting better, but I still get a fair number of people coming by with a missing wp_footer, which is where Thickbox gets added.
Thanks again, and cheers!
Byron
Hi Ronald,
You mentioned this:
“Another “sin” I didn’t mention is people who still use the “onload” event.”
Can you enlighten me on why this a sin when adding a script to WP?
After searching for nearly 30 mins to get the syntax so i could understand what the true and false were being used for this article is the clearest and easiest to understand. Many Thanks it’s helped me to load jquery and jquery-ui.min from google and place it in the footer.
Great work thanks for sharing,
Ian
Awesome article, I love it!!!
I had so many problems with my plugin, because of jquery, now it’s all solved