Skip to content

Instantly share code, notes, and snippets.

@racmanuel
Created May 20, 2021 23:14
Show Gist options
  • Save racmanuel/9f5ffc3c192108b4b262fe304b9fb6e0 to your computer and use it in GitHub Desktop.
Save racmanuel/9f5ffc3c192108b4b262fe304b9fb6e0 to your computer and use it in GitHub Desktop.
Enqueue custom styles and scripts in various especific URL in WordPress Theme
<?php
function enqueue_scripts_and_styles(){
//Enqueue custom styles and scripts in various especific URL in WordPress Theme
$urls = array(
'dashboard',
'dashboard/product',
'dashboard/order',
'dashboard/settings',
'dashboard/rating',
'dashboard/refund_request',
);
foreach ($urls as $url => $url_result) {
if (strpos($_SERVER["REQUEST_URI"], $url_result) != false) {
//url contains 'dashboard/array($urls)'
wp_enqueue_style('dashboard', get_stylesheet_directory_uri() . '/assets/css/dashboard.css', array(), '1.0', 'all');
}
}
}
add_action('wp_enqueue_scripts', 'enqueue_scripts_and_styles', 11);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment