WordPress函数解析:wp_head

wp_head

该函数并没有什么实际功能,查看源代码可以得出它只是埋下了一个wp_head钩子而已,但是WordPress再开始运行的时候像这个钩子注入了很多功能,例如头部的css、js、title、meta等标签。

源码

File: wp-includes/general-template.php 3003行

function wp_head() {
    /**
     * Prints scripts or data in the head tag on the front end.
     *
     * @since 1.5.0
     */
    do_action( 'wp_head' );
}

列子

一个WordPress主题文件的header.php文件如下:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <?php wp_head(); ?>
</head>
<body>

注意:在开发WordPress主题的时候,应该在你的header.php文件中都写上该函数,以便你的主题可以良好的二次开发和维护!

更多WordPress函数解析、实用例子尽在WordPress代码库

猜你喜欢

转载自blog.csdn.net/qq_22502303/article/details/117262481