This article mainly introduces the method of using wp_head() function in WordPress. It has certain reference value. Now I share it with you. Friends in need can refer to
Use this function in WordPress themes to control the tag content between <head>
…</head>
.
To output the head tag part in html through the header.php template file,
wp_head is added to the head tag of most themes () function,
WordPress, themes or plug-ins can add content to the head tag of the website by giving the wp_head function.
Please make sure all your pages use <?php wp_head(); ?>
The header.php template of many themes supports the wp_head()
function by default. If it is not supported, you can add it yourself. The adding method is as follows:
Add <?php wp_head(); ?>
between
<head>
…
You can dynamically add code to <head></head> when making a plug-in, such as advertising code, etc.
function my_wp_head() { echo "<link rel='stylesheet' href='../Avada-Child-Theme/css/test.css' type='text/css' />"; echo '<meta name="关键字" content="测试内容" />'; } add_action('wp_head', 'my_wp_head');
Open any front-end page, right-click "View Source Code" and search for the entered content. If it appears, it means success.
Generally, after the modification is successful, you have to wait for a while to refresh. If you enable cache/use cache plug-ins, you need to clear the cache.
Correspondingly, we will have wp_footer() and wp_sidebar() functions. The usage method is the same as above.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Introduction to adding fixed fields to articles in wordpress
The above is the detailed content of How WordPress uses the wp_head() function. For more information, please follow other related articles on the PHP Chinese website!