wp_register wp_enqueue
-
Hi all,
once again I wish to go back to the functions “
wp_enqueue_script
” and “wp_register_script
” (or style).In several publications I read that recently is no longer needed to register a new code, and that the “enqueue” method is enough for the whole job:
actually from https://developer.www.ads-software.com/reference/functions/wp_enqueue_script/ it seems that it is correct to add parameters (handle, src, array, etc.) directly to “
wp_enqueue_ ..
” function.But in other publications (f.e. https://gloriathemes.com/wordpress-enqueue-scripts-and-styles/) it is stated that “to use the hook “
wp_enqueue_scripts
” it is correct to use “enqueue” method only after “registered” the code: it could be that they are old publications (in fact I dislike when a publisher doesn’t put a date) but on the web there is too much controversial information on this issue.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.
For temporary the solutions which I have decided are as follows:
- To override previous parent theme scripts (replacement with same file name) I deregister > register new one > then enqueue (register with the five arguments and enqueue just with file name as handle)
- For my new codes valid for whole website I register them and then enqueue
- For my new codes for specific pages (enqueued conditionally) I directly enqueue them (with handle , path)
- In general I enqueue / register multiple codes per single function, keeping them separately when I need to give some priority to the “
add_action(hook)
”.
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).
(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’s script is automatically overridden by the child’s script .. hence it results to me that using parallel paths with same structure the deregistration process is automatic)
Mauro
- The topic ‘wp_register wp_enqueue’ is closed to new replies.