The main difference is the location where the style (link
) or script tag be in the source, or whether the resource is loaded in head
or the footer.
-
With a
add_menu_page()
/add_submenu_page()
callback like yourfoo_settings_page()
, the style/script file would be loaded in thebody
(before the closingbody
tag), because thehead
has already been rendered by the time that the callback (foo_settings_page()
) is called:<body> ... the content of your plugin page (added through foo_settings_page()) ... ... <!-- The style/script file would be loaded here, in the footer. --> </body>
-
With your
foo_admin_enqueue_scripts()
which is aload-<page hook>
callback, the style/script file would be loaded in thehead
— but for a script, it could be in the footer; check the fifth parameter forwp_enqueue_script()
:<head> ... <!-- The style/script file would be loaded here, unless if the *script* is set to be loaded in the footer. --> ... </head>
And I know there are certain cases where you need to load a style/script file right after a specific element is rendered on the page, but in most cases, style files should be loaded in head
and script files in the footer — although in these modern days, scripts may be put in the head
.