{"id":16754983,"date":"2023-05-21T10:43:22","date_gmt":"2023-05-21T10:43:22","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/wp_register-wp_enqueue\/"},"modified":"2023-05-21T11:19:16","modified_gmt":"2023-05-21T11:19:16","slug":"wp_register-wp_enqueue","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/wp_register-wp_enqueue\/","title":{"rendered":"wp_register wp_enqueue"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi all,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">once again I wish to go back to the functions &#8220;<code>wp_enqueue_script<\/code>&#8221; and &#8220;<code>wp_register_script<\/code>&#8221; (or style).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In several publications I read that recently is no longer needed to register a new code, and that the &#8220;enqueue&#8221; method is enough for the whole job:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">actually from <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_enqueue_script\/\">https:\/\/developer.wordpress.org\/reference\/functions\/wp_enqueue_script\/<\/a> it seems that it is correct to add parameters (handle, src, array, etc.) directly to \u201c<code>wp_enqueue_ ..<\/code>\u201d function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But in other publications (f.e. <a href=\"https:\/\/gloriathemes.com\/wordpress-enqueue-scripts-and-styles\/\">https:\/\/gloriathemes.com\/wordpress-enqueue-scripts-and-styles\/<\/a>) it is stated that \u201cto use the hook \u201c<code>wp_enqueue_scripts<\/code>\u201d it is correct to use \u201cenqueue\u201d method only after \u201cregistered\u201d the code: it could be that they are old publications (in fact I dislike when a publisher doesn\u2019t put a date) but on the web there is too much controversial information on this issue.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In child theme functions.php I tested both ways, and both work fine for me, but still not clear which one is the appropriate method today.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For temporary the solutions which I have decided are as follows:<\/p>\n\n\n\n<ol>\n\n<li>To override previous parent theme scripts (replacement with same file name) I deregister &gt; register new one &gt; then enqueue (register with the five arguments and enqueue just with file name as handle)<\/li>\n\n\n<li>For my new codes valid for whole website I register them and then enqueue<\/li>\n\n\n<li>For my new codes for specific pages (enqueued conditionally) I directly enqueue them (with handle , path)<\/li>\n\n\n<li>In general I enqueue \/ register multiple codes per single function, keeping them separately when I need to give some priority to the \u201c<code>add_action(hook)<\/code>\u201d.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">I kindly ask if my above methods (from 1 to 4) are the appropriate ones according to recent standards of WP: in my opinion it is useful to clarify for everyone (thanks in advance).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(PS: I also repeat that, even if recently applied the deregister\/register method, if you change a theme script is assets\/js using the same script name, the parent&#8217;s script is automatically overridden by the child&#8217;s script .. hence it results to me that using parallel paths with same structure the deregistration process is automatic)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mauro<\/p>\n","protected":false},"template":"","class_list":["post-16754983","topic","type-topic","status-publish","hentry","topic-tag-deregister","topic-tag-enqueue","topic-tag-register"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16754983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16754983\/revisions"}],"predecessor-version":[{"id":16755036,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16754983\/revisions\/16755036"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16754983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}