The first argument of preg_match
is supposed to be a pattern, not a string, so it’s probably not comparing the way you expect. Use strpos
instead:
function wpse_275760_theme_scripts() {
global $wp_scripts;
$stylesheet_uri = get_stylesheet_directory_uri();
foreach( $wp_scripts->queue as $handle ) {
$obj = $wp_scripts->registered[$handle];
$obj_handle = $obj->handle;
$obj_uri = $obj->src;
if ( strpos( $obj_uri, $stylesheet_uri ) === 0 ) {
echo $obj_handle;
} else {
echo 'NOTHING Match';
}
}
}
strpos()
returns the starting position of the match, if there is one. Comparing with ===
to 0
ensures that the script URL and theme URL match from the beginning, which is what you want, since they will both start with http://mydomain/wp-content/themes/mytheme
.
Related Posts:
- Trigger a php file on every post or page if a condition is met
- Enqueue less file not working in child theme?
- Execute only on a certain page
- How to execute a simple php script in WP (I don’t think wp_enque_script applies here)
- Is it recommended to pass some data to scripts in `wp_enqueue_scripts`?
- if file_exists not working with wp_enqueue_style
- enqueue hover function
- Adding tawk.to code just before body tag on functions.php file
- How to enqueue CSS and JS only on specific template?
- Deregistering a script in WordPress seems impossible
- How to inject variables into public-facing JS using wp_enqueue_script
- How to only enqueue script if it’s a post
- WordPress Scripts Being Loaded in Footer
- Jquery function working in Dev Console but not otherwise [duplicate]
- jQuery code not working when included in functions.php
- Conditional Javascript based on WP Version
- Is the wp_enqueue method efficient?
- Correct way to enqueue page specific CSS file
- linking stylesheets and scripts with functions.php
- Double jQuery loaded
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- How to use wordpress function wp_enqueue_script() in php?
- Enqueing External JS on the remote server JS
- Trying to enqueue script – Nothing Happens
- url_to_postid returns 0
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- Enqueueing a code block from an options framework
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Using Google Analytics in an enqueued JS file
- Enqueue assets from multiple directories using add_action/do_action
- How to change order inside foreach using wp_enqueue_script?
- Call a single function on two different methods with hooks
- Enqueue sripts and styles only if function is called
- Load script and styles using an array of resources
- Importing the style and scripts in the plugin doesn’t work as well as in the theme
- When to use wp_register_script() function?
- How to stop loading my custom scripts files for wordpress iframe?
- How can I enqueue comment-reply script only on certain page?
- Chosen Select jquery Not Working in Plugin
- Adding javascript files to WordPress and jQuery version
- How can I print out a single stylesheet or javascript link?
- Adding Gravity Form With if(is_page) Is Not Working
- wp_enqueue_style conflict when using in different action hooks
- Errors while Loading Most Recent Version of jQuery
- Warning: filemtime(): stat failed for wp_
- How to enqueue structured data as file – jsonld file seems not to work
- Make a variable global and use it for inline script
- functions.php doesn’t load all custom theme assets
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- Uninstalling a plugin: delete all options with specific prefix
- Can i check if user is doing any ajax request?
- WordPress customizer: load controls in a custom div
- Is it unsafe to put php in the /wp-content/uploads directory?
- How to Populate the list of custom post type categories
- Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- Understanding WordPress child theme custom JS loading
- Problem with ACF shortcode with Repeater Field in WordPress? [closed]
- How to make a variable available for the duration of the page request
- When would you use $_post instead of $post?
- Autogenerate shortcodes from an array of strings
- Remove annoying WP Adminbar CSS
- wp_kses and magic quotes
- Customize Plugin
- display month in french in wordpress/php?
- Retrieving Author ID in wp-admin area
- Custom Theme, Custom shortcode not working
- Adding custom directory and PHP files in wordpress
- Options API get_option() and update_option() Not Correctly Updating or Returning
- Not connecting to database in file with multiple MySQL connections
- Way to bulk make all my tags lowercase?
- Create a Blog Template Page
- How to make widget title accept php?
- Function works everywhere, how to keep it to execute when creating a new post
- How do I create a numbered list with PHP? [closed]
- HTML table attributes ignored
- How can i change variable if condition is not met
- Reading settings in the home page precisely home.php
- How to display author above content-single.php post
- Calling function in loop causes repeat data
- How can I include the user id inside of a shortcode php output?
- How to use wp_nav_menu to create custom dropdown menu?
- how to get attached file url for current post?
- Is there a hack for using is_page() within the function.php file?
- WordPress Search Ajax + Isotope + InfiniteScroll
- WordPress create custom XML RSS feed template
- Require()/Include() post template adding extra content
- display most active user sort by comment count [Solved]
- Approval by Admin to confirm the change
- Check if post visited first time
- Help with preg_replace
- Store custom field’s multiple values in one user meta key
- Advertisement in Loop Posts wordpress
- WooCommerce multiple custom fields code
- Pass form attributes to another php template in wordpress
- WP_Widget dynamic field array with external AJAX
- Programmatically change post templates? [duplicate]
- How to combine array info [closed]
- Select area and checkbox data is not saving?
- Suppress errors when using global function
- In reading settings posts are set to “blog” and I have page-blog.php but no posts