$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - How does WordPress differentiate what scripts are loaded in wp_head() and wp_footer()?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How does WordPress differentiate what scripts are loaded in wp_head() and wp_footer()?

matteradmin8PV0评论

A newbie question. I have gone through the wp_head() and wp_footer() documentation and both are said to be including the scripts and styles. So my question is how does WordPress differentiate which scripts need to be in the wp_head() and which needs to be in wp_footer(). My understanding is that the wp_head() will include all the scripts and styles in the header section of the webpage, and calling the wp_footer() will again include the same scripts and styles in the footer section of the website. I know it is wrong.

A newbie question. I have gone through the wp_head() and wp_footer() documentation and both are said to be including the scripts and styles. So my question is how does WordPress differentiate which scripts need to be in the wp_head() and which needs to be in wp_footer(). My understanding is that the wp_head() will include all the scripts and styles in the header section of the webpage, and calling the wp_footer() will again include the same scripts and styles in the footer section of the website. I know it is wrong.

Share Improve this question asked Feb 10, 2019 at 6:14 Denny PaulDenny Paul 1112 bronze badges 3
  • scripts are loaded whereever the wp_scripts() or wp_script() is loaded I guess, they're not part of wp_head or wp_footer, sorry I've forgotten the exact function name, I think it's wp_scripts – Aurangzeb Commented Feb 10, 2019 at 6:20
  • 1 Read through this: developer.wordpress/reference/functions/wp_enqueue_script There’s a parameter $in_footer – muka.gergely Commented Feb 10, 2019 at 6:22
  • 1 I don't understand why there is a down-vote for question. – user3864263 Commented Feb 10, 2019 at 6:30
Add a comment  | 

1 Answer 1

Reset to default 2

wp_enqueue_scripts has a parameter which specifies if the script should be rendered in wp_head or wp_footer

The function signature is this:

wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Note that it is the 5th parameter, so if you wish to not have any dependencies and use the default version number for your script you still have to supply those parameters. For example:

wp_enqueue_script( 'your_script_name', 'your_script_location', array(),false, true );
                                                                                ^     
                        //  This will cause the script to render in wp_footer   | 
Post a comment

comment list (0)

  1. No comments so far