#32607 closed feature request (invalid)
Function for URL to registered scripts and styles
| Reported by: | msnewton | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Script Loader | Version: | |
| Severity: | normal | Keywords: | has-patch reporter-feedback close |
| Cc: | Focuses: |
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)
@
11 years ago
Introducing wp_get_registered_script() and wp_get_registered_style(). Including unit tests.
#2
@
11 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
@
10 years ago
- Keywords reporter-feedback added
- Summary Function for URL to registers scripts and styles → 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?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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_scriptsfor 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_Dependencyobject (containinghandle- script/style name,src- URL,deps- dependancies,ver- version, etc.), orfalseif the script/style hasn't been registered.I'll attach a patch for these functions in a minute.