#32607 closed feature request (invalid)
Function for URL to registered scripts and styles
Reported by: | msnewton | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | has-patch reporter-feedback close |
Focuses: | Cc: |
Description
I would like to see a function that would return the full URL to a script or style registered with wp_register_script() or wp_register_style(), or those that are “built-in” to WP.
The reason is this: I generate all of the HTML for special pages myself but wish to include standard scripts and styles that are built in to WordPress. Rather than relying upon a fixed filepath to remain static, and assuming it won't change in future versions, I'd like to ask WP to tell me where it is.
Attachments (1)
Change History (8)
@
9 years ago
Introducing wp_get_registered_script()
and wp_get_registered_style()
. Including unit tests.
#2
@
9 years ago
- Keywords has-patch added
Here is an example usage with the functions from my patch:
// registering a script wp_register_script( 'handle', 'http://example.com', array( 'test-dep' ), 1 ); // retrieving various details for the 'handle' script $script = wp_get_registered_script( 'handle' ); echo $script->src; // script URL echo $script->ver; // script version
So this way you could easily retrieve the entire script/style dependancy object, and quickly get the URL, version, dependancies or anything else from it.
#4
in reply to:
↑ description
@
8 years ago
- Keywords reporter-feedback added
- Summary changed from Function for URL to registers scripts and styles to Function for URL to registered scripts and styles
Replying to msnewton:
The reason is this: I generate all of the HTML for special pages myself but wish to include standard scripts and styles that are built in to WordPress.
Adding <?php wp_head(); ?>
before </head>
and <?php wp_footer(); ?>
before </body>
should do that, unless I'm missing something. Why do you need a new function?
#5
@
9 months ago
- Keywords close added
As there's been no reply in 7 years, I'm marking this as a close candidate.
If there is no response in the next 30 days, this ticket will be closed (it can be reopened at any time in the future if needed).
Hi @msnewton and welcome to the WordPress Core Trac!
This sounds like a good idea IMHO. I've personally had to locate the URL or version of a registered script several times and I always had to use the global variables
$wp_scripts
for these instances.So, it might be useful to be able to quickly find the URL, version or dependancies of a style/script that has been registered.
The functions for that can simply return the
_WP_Dependency
object (containinghandle
- script/style name,src
- URL,deps
- dependancies,ver
- version, etc.), orfalse
if the script/style hasn't been registered.I'll attach a patch for these functions in a minute.