[Plugin: Basic Comment Quicktags] Change Quicktags JavaScript File URL
-
I am serving all my static content from a different domain, and am facing one small problem with the plugin (NOT a bug, just my problem).
The quicktags JS file (
http://example.com/wp-includes/js/quicktags.js) is being served from the same domain as my website. How can I have it served from a different domain, say,example2.com?I tried deregistering, then changing the src of the file, and enqueuing
quicktags, but that seems to be messing with the plugin.It would be great if someone can provide me the function that allows me to properly change the URL of the quicktags core JS file.
-
Huh. Well, the catch there is that most (well written) plugins are relatively looking for your wp-content folder. In this case, I used plugin_dir_url:
wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1);It should be rendering as
http://example.com/wp-content/plugins/basic-comment-quicktags/quicktags.jsby the way…So is the issue that your wp-content is in another location? How are you telling WP right now where to go for Static Content? If you’d used a define in your wp-config, that should have been picked up.
Hello Mika,
I am talking about
wp-includesand NOTwp-contentdirectory. And since you asked, I’ve set a different domain for thewp-contentdirectory by adding this in my wp-config.php:define( 'WP_CONTENT_URL', 'http://static-content.com/wp-content');But that doesn’t change the URLs of JavaScript files loaded from
wp-includesto the new domain. And as there’s no such thing asWP_INCLUDES_URL, I have to manually un/de-register each handle and have it enqueued with the static domain (from the e.g. static-content.com).The handle for
http://example.com/wp-includes/js/quicktags.jswhich the Basic Comment Quicktags plugin uses (as a dependency) isquicktags, and trying to un/de-register the handle and enqueuing it with the static domain somehow breaks the plugin’s CDATA JS output in the footer.What I am asking is, what is the proper way to have this file β
http://example.com/wp-includes/js/quicktags.jsβ served from the domain that serves static files, i.e. like this βhttp://static-domain.com/wp-includes/js/quicktags.jsI would be very helpful if you can give me the proper function/code to un-register and enqueue the handle (quicktags), as my method seems to break the plugin.
Hope I am clear enough this time. π
Yeah, that’s this part
array("quicktags","jquery")That’s WP’s own code, and … you’d have to move it. You’d have to deregister quicktags itself and register your own for that.
Yes, that’s what I am asking. How do I do that? Something’s wrong with the way I am doing it. This is what I’ve tried (and some variants of it as well, actually):
add_action('wp_enqueue_scripts','aahan_register_script'); function aahan_register_script(){ wp_deregister_script('quicktags'); wp_register_script('quicktags', 'http://static-domain.com/wp-includes/js/quicktags.js', false, false); wp_enqueue_script( 'quicktags' ); }Is something wrong with the way I am doing it?
OR it would be great if you can tell me how to replace this function (from your plugin) with some code in my function.php (sorry, I am not that good with PHP, but I am just into learning it):
function ippy_bcq_add_scripts() { $options = get_option('ippy_bcq_options'); $valuebb = $options['bbpress']; $valueco = $options['comments']; $ippy_bcq_bbp_fancy = get_option( '_bbp_use_wp_editor' ); if ( function_exists('is_bbpress') ) { if ( is_bbpress() && ( $valuebb != '0') && !is_null($valuebb) && ($ippy_bcq_bbp_fancy == '0') ) { wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1); wp_enqueue_style("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.css", false, "1.8"); wp_print_styles('editor-buttons'); } } if ( comments_open() && is_singular() && ( $valueco != '0') && !is_null($valueco) ) { wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1); wp_enqueue_style("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.css", false, "1.8"); wp_print_styles('editor-buttons'); } } if( !is_admin() ) { add_action('wp_print_styles', 'ippy_bcq_add_scripts'); }What you have two posts up should work.
I wonder if my code is getting called before yours and that’s why…I’d try setting a lower priority.
Or if I was really lazy, an .htaccess rule to redirect that file.
What file are you putting that code in? Your themes functions.php?
Yes, in my theme functions.php.
EDIT: I also tried lower priority numbers (as low as 1). Doesn’t change anything.
By the way, I also tried using
wp_print_stylesinstead ofwp_enqueue_scripts, still no luck.*ponder*
Why not move the plugins directory back?
define( 'WP_PLUGIN_URL', 'http://example/wp-content/plugins');I suggest this because plugins (and themes) aren’t ‘static’ content. The intent of the WP_CONTENT_URL changability is to move your content from /home/aahan/public_html/wp-content/ to /home/aahan/wp-content/ (i.e. outside of ‘root’) which makes things unlinkable and more secure (arguably). I’m not entirely sure totally changing the domain was the intent.
π Sad, but kinda makes sense. Thanks for your time Mika π
After lots of looking into files, and asking questions, it finally struck me… this is how it needs to be done:
add_action('wp_enqueue_scripts','aahank_register_script'); function aahank_register_script(){ //Re-register quicktags script wp_deregister_script('quicktags'); wp_register_script('quicktags', 'http://static-content.com/wp-includes/js/quicktags.js', false, false, true); wp_localize_script( 'quicktags', 'quicktagsL10n', array( 'wordLookup' => __('Enter a word to look up:'), 'dictionaryLookup' => esc_attr(__('Dictionary lookup')), 'lookup' => esc_attr(__('lookup')), 'closeAllOpenTags' => esc_attr(__('Close all open tags')), 'closeTags' => esc_attr(__('close tags')), 'enterURL' => __('Enter the URL'), 'enterImageURL' => __('Enter the URL of the image'), 'enterImageDescription' => __('Enter a description of the image'), 'fullscreen' => __('fullscreen'), 'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ), 'textdirection' => esc_attr( __('text direction') ), 'toggleTextdirection' => esc_attr( __('Toggle Editor Text Direction') ) )); }As for the code used in
wp_localize_script, I got it straight from source: http://core.svn.ww.wp.xz.cn/trunk/wp-includes/media.phpPS: Cross-posted from http://wordpress.stackexchange.com/q/56742/10691
Yow! What a hassle π
The topic ‘[Plugin: Basic Comment Quicktags] Change Quicktags JavaScript File URL’ is closed to new replies.