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
- in_footer: gives syntax error
- WordPress generating Undefined Variable warning
- WP E-commerce: Showing 3 random products from current category when viewing product
- If Custom Field is empty don’t display div
- error_log is not working as expected in functions.php file
- WordPress template_include filter not working properly
- Web scraping using transients
- doing an ajax request always outputs 0
- What is the intended purpose of the _wp_attachment_context post meta key?
- Why the JavaScript code is ignored from wp editor?
- Why does my callback function not work with this custom filter hook?
- Get and insert order email address to the PHP template inside HTML text
- Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
- Send an email to specific adress when button is clicked?
- PHP version problem?
- wp-options keep crashing please help
- Post’s ID pattern?
- Countdown to date function?
- calling a custom field value inside functions.php
- WordPress check if current taxonomy has child
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- show something only when user comes from specific page at remote host?
- Adding php script to WordPress [closed]
- Remove category from pagination
- Function Display article [closed]
- Conditional On custom field plugin metabox
- Exclude function from running on a certain page
- wordpress sql posts query won’t display the latest post in a specific category
- How to load previous or next attachment with jquery ?
- duplicate posts with ajax load more wordpress
- Using ACF Relationship field to set post type to draft or published status
- Posts page (category) layout modification, which php file change?
- Merge wp_get_post_terms
- Huge time to first byte on live site
- CPT in a shortcode
- All categories options or All categories not Populating
- WordPress load javascript file if something… (after the page is loaded)
- WordPress Shortcode based on other shortcode
- Force CSV download with template_redirect
- Exclude Post ID from Array Specified in Custom Field
- Hide button based on PHP result
- WordPress create new on site when a new page is added
- Why does a meta_query break this WP_Query?
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- Create an if statement based on page_id
- Require Credits Footer
- Undefined variable notice [closed]
- Suddenly sessions and header location not working
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Adding extra cost to woocommerce flat rate based on shipping zone
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- How can I display a Divi content inside a modal based on an AJAX request