Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 7, 2018 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/17a50a2d658c3d67e5d1603e3901f987 to your computer and use it in GitHub Desktop.
Save wpscholar/17a50a2d658c3d67e5d1603e3901f987 to your computer and use it in GitHub Desktop.
Fix plugin URLs for plugins inside the theme
<?php
/**
* Fix plugin URLs for plugins inside the theme
*/
add_filter( 'plugins_url', function ( $url, $path, $plugin ) {
$theme_path = trailingslashit( wp_normalize_path( get_theme_file_path() ) );
if ( 0 === strpos( $plugin, $theme_path ) ) {
$basename = trim( dirname( str_replace( $theme_path, '', $plugin ) ), '/' );
$url = get_theme_file_uri( "$basename/$path" );
}
return $url;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment