Similar to Wyck’s answer, but using str_replace instead of regex.
script_loader_src
and style_loader_src
are the hooks you want.
<?php
add_filter( 'script_loader_src', 'wpse47206_src' );
add_filter( 'style_loader_src', 'wpse47206_src' );
function wpse47206_src( $url )
{
if( is_admin() ) return $url;
return str_replace( site_url(), '', $url );
}
You could also start the script/style URLs with a double slash //
(a “network path reference“). Which might be safer (?): still has the full path, but uses the scheme/protocol of the current page.
<?php
add_filter( 'script_loader_src', 'wpse47206_src' );
add_filter( 'style_loader_src', 'wpse47206_src' );
function wpse47206_src( $url )
{
if( is_admin() ) return $url;
// why pass by reference on count? last arg
return str_replace( array( 'http:', 'https:' ), '', $url, $c=1 );
}
Related Posts:
- Removing specific style from wp_head
- Track down where script is being enqueued from
- Wp_head and wp_footer vs wp_enqueue_script javascript files?
- How to use wp_enqueue_style() and wp_enqueue_script() only when needed?
- Remove specific CSS and JS from the head
- wp_head() – list hooked actions with priorities?
- Custom script file enqueue has “?ver=4.5.1” when loading and doesn’t update
- How can I remove the site URL from enqueued scripts and styles?
- wp enqueue style on specific page templates
- How do I get the $handle for all enqueued scripts?
- How can I get a list of all enqueued scripts and styles?
- Load CSS/Javascript in frontend conditionally if block is used
- Register a script to be enqueued both in admin and front end
- Cannot deregister a script using wp_deregister_script
- Conditional wp_enqueue_script on a page
- Enqueue custom font file with rel=”preload”
- How do I force wp_enqueue_scripts to load at the END of ?
- How to dequeue / deregister any theme styles and scripts
- Why is jquery-ui-core enqueueing in my footer instead of the header?
- Using wp_enqueue_script on shortcode function handler
- Enqueue script only for IE
- Conditionally dequeue dependency of scripts
- Enqueue script only if page has an oembed
- It would be a right way to enqueue the script using foreach loop?
- Is this a bad implementation of wp_enqueue_script for conditional usage?
- Remove a script from a template file using wp_dequeue_script
- wp_enqueue_script vs. wp_register_script
- How to dequeue / deregister parent theme style
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- Enqueue script on specific WooCommerce template
- Move all the JS files to the bottom|footer, the right way
- Enqueueing Scripts on a Custom Top-level Menu Page
- Select2 in WordPress
- How to switch css files according to devices and button click?
- How to control the order of the combination of enqueued styles and scripts – site speed issue
- Performance-wise, is it better to enqueue a (small) script on every page or test to see if it’s needed?
- scripts not enqueueing
- Stop WordPress editor embedding links
- How can I make sure my JS script gets executed first, among other scripts?
- How to load script-related styles automatically?
- How to cancel `wp_print_scripts`?
- Do we have to register JQuery if we want to use it in wp_enqueue_script()?
- Retrieve URL of Script/Style and Dependencies
- wp_enqueue_script called incorrectly
- using conditionals on enqueue styles
- How to change script order?
- Enqueue script multiple times?
- Including files in Child Themes
- Can’t load JS File
- Exclude external uri for css and js version
- Do I need to register my own created .js and .css files
- How to enqueu php files with custom variable & conditionals?
- How to add parameter to wp_enqueue_script?
- Change script type and src of plugins in theme
- How to enqueue the script without hardcoded in the theme files?
- Why is .map being added to the end of my file path?
- How can I properly enqueue tags in WordPress to use with Web Components?
- get_template_directory_uri() gives me wrong path when I try to use wp_enqueue_style
- Overwrite wp_enqueue_script under certain condition
- Enqueuing script is adding extra text for google maps [closed]
- get_stylesheet_directory() in child theme breaks parent scripts
- Enqueueing Scripts and Styles
- Not all my scripts are enqueueing
- JavaScript is not enqueuing
- browser showing connection was reset while accessing posts from local host
- Enqueue scripts based on options
- How to use wp_enqueue_script, style when required
- Enqueue Script in WordPress
- how to enqueu customiser/customizer scripts?
- how to enqueue javascript to manipulate acf input field in admin?
- Plugin add_action and add_menu_page
- add WordPress script to page conditionally by category
- load a different stylesheet in a category post
- I want to set global directory locations for my CSS and JS locations. How?
- How to register script with null value for version?
- Fatal error: Call to undefined function wp_enqueue_media()
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- thickbox never gets called (weird behavior)
- How to do chunked JS files in WordPress?
- Copy permalink to clipboard automatically when publish/update posts?
- WordPress wp_enqueue_style and wp_enqueue_script not working
- Stylesheets and scripts not loading
- Enqueue registered dependencies only when necessary
- Scripts and stylesheets failing to load in Chrome IOS (and only Chrome IOS)
- wp_enqueue_scripts action from a plugin overrides theme wp_enqueue_scripts no matter what the priority setting
- i can’t handle any style or Js file on my theme . what is the problem of this file?
- ajax jquery live search box not working in wordpress plugin
- Dealing with multiple Google maps API calls
- Proper use of wp_localize_script?
- Prevent caching when using wp_enqueue_script?
- Should I be enqueueing styles/scripts once and then dequeueing them?
- Initializing scripts in wordpress
- wp_enqueue_script was called incorrectly… i want to work with debug on
- Loop through arguments of a function
- css3-mediaqueries-js failing with child theme
- Enqueueing Script to footer puts it at the very bottom
- wp_enqueue_scripts hangs
- Using wp_enqueue_script in a wordpress plugin
- How to enqueue js script after another specific js script?
- Dequeue/deregister scripts for everybody but the administrator