Skip to content

Commit 600befa

Browse files
NielsdeBlaauwjrfnlGaryJones
authored
Adds documentation for WordPress.WP.EnqueueResourceParameters. (#1825)
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> Co-authored-by: Gary Jones <github@garyjones.io> Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
1 parent 2b4ba59 commit 600befa

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<documentation title="Enqueued Resource Parameters">
2+
<standard>
3+
<![CDATA[
4+
The resource version must be set, to prevent the browser from using an outdated, cached version after the resource has been updated.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: Resource has a version number.">
9+
<![CDATA[
10+
wp_register_style(
11+
'someStyle-css',
12+
$path_to_local_file,
13+
array(),
14+
<em>'1.0.0'</em>
15+
);
16+
]]>
17+
</code>
18+
<code title="Invalid: Resource has no version number set.">
19+
<![CDATA[
20+
wp_register_style(
21+
'someStyle-css',
22+
$path_to_local_file,
23+
array()
24+
);
25+
]]>
26+
</code>
27+
</code_comparison>
28+
<standard>
29+
<![CDATA[
30+
The resource version must not be `false`. When this value is set to `false`, the WordPress Core version number will be used, which is incorrect for themes and plugins.
31+
]]>
32+
</standard>
33+
<code_comparison>
34+
<code title="Valid: Resource has a version number.">
35+
<![CDATA[
36+
wp_enqueue_script(
37+
'someScript-js',
38+
$path_to_local_file,
39+
array( 'jquery' ),
40+
<em>'1.0.0'</em>,
41+
true
42+
);
43+
]]>
44+
</code>
45+
<code title="Invalid: Resource has version set to false.">
46+
<![CDATA[
47+
wp_enqueue_script(
48+
'someScript-js',
49+
$path_to_local_file,
50+
array( 'jquery' ),
51+
<em>false</em>,
52+
true
53+
);
54+
]]>
55+
</code>
56+
</code_comparison>
57+
<standard>
58+
<![CDATA[
59+
You must explicitly set a JavaScript resource to load in either the header or the footer of your page. It is recommended to load these resources in the footer by setting the `$in_footer` parameter to `true`.
60+
61+
Loading scripts in the header blocks parsing of the page and has a negative impact on load times. However, loading in the footer may break compatibility when other scripts rely on the resource to be available at any time.
62+
In that case, you can pass `false` to make it explicit that the script should be loaded in the header of the page.
63+
]]>
64+
</standard>
65+
<code_comparison>
66+
<code title="Valid: The resource is specified to load in the footer.">
67+
<![CDATA[
68+
wp_register_script(
69+
'someScript-js',
70+
$path_to_local_file,
71+
array( 'jquery' ),
72+
'1.0.0',
73+
<em>true</em>
74+
);
75+
]]>
76+
</code>
77+
<code title="Invalid: The location to load this resource is not explicitly set.">
78+
<![CDATA[
79+
wp_register_script(
80+
'someScript-js',
81+
$path_to_local_file,
82+
array( 'jquery' ),
83+
'1.0.0'
84+
);
85+
]]>
86+
</code>
87+
</code_comparison>
88+
</documentation>

0 commit comments

Comments
 (0)