Created
May 20, 2021 23:14
-
-
Save racmanuel/9f5ffc3c192108b4b262fe304b9fb6e0 to your computer and use it in GitHub Desktop.
Enqueue custom styles and scripts in various especific URL in WordPress Theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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