I hope your greate, i have some issues with loading separate files based on url variable in wordpress. I thought it would be best to do this in the child theme functions file. code below:
$getURLVar = explode("/",$_SERVER['REQUEST_URI']);
if($getURLVar[1] == "temp"){
$uri_based_style = 'style-temp.css';
} else {
$uri_based_style = 'style.css';
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles',999 );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . $uri_based_style,
array( $parent_style )
);
}
I cant get it to load the file.
Both css files are based in the child theme dir.
Does anybody have a clue ?
Best Regards
Your issue is the variable scope. You’ve defined the variable outside of the function, so it’s not available by default inside the function. For simplicity sake, just declare it inside the function, like so:
Alternatively…
If for some reason you really want / need to declare it outside the function, use
global
, like so: