Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Last active January 26, 2024 02:21
Show Gist options
  • Save hsleonis/f780a84f0641a77549ad to your computer and use it in GitHub Desktop.
Save hsleonis/f780a84f0641a77549ad to your computer and use it in GitHub Desktop.
WordPress change default stylesheet location
<?php
/*
Add these code to your functions.php
This will only change the stylesheet/stylesheet dir uri
But will not add theme info from the new location
To fix you must place another style.css with theme information in theme root directory (i.e: wp-content/themes/twintysixteen/)
*/
add_filter('stylesheet_uri','wpi_stylesheet_uri',10,2);
/**
* wpi_stylesheet_uri
* overwrite default theme stylesheet uri
* filter stylesheet_uri
* @see get_stylesheet_uri()
*/
function wpi_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri){
return $stylesheet_dir_uri.'/css/mytheme.css';
}
add_filter('stylesheet_directory_uri','wpi_stylesheet_dir_uri',10,2);
/**
* wpi_stylesheet_dir_uri
* overwrite theme stylesheet directory uri
* filter stylesheet_directory_uri
* @see get_stylesheet_directory_uri()
*/
function wpi_stylesheet_dir_uri($stylesheet_dir_uri, $theme_name){
$subdir = '/css';
return $stylesheet_dir_uri.$subdir;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment