首页 > 解决方案 > How to build the head tag?

问题描述

I am building a custom template page and I'd like to add things in the <head> tag while having the Wordpress header.

get_header will add the <head> tag and the actual header in the <body> portion.

How can I be more precise to build the page mixing Wordpress elements and my custom elements in both the <head> and <body> tags?

For example, I'd like to add the <title> tag myself because it's dynamic and add some CSS/JS to load.

Note that I am not building a theme or want to edit a theme. I want to reuse the current theme. I am creating a plugin that adds a custom page and I want to reuse the installed theme + do some custom additions in the header only for my custom page.

标签: wordpresswordpress-themingcustom-wordpress-pages

解决方案


我最终使用其中一个钩子来删除标题,然后回显我想要添加到<head>标签中的所有内容。

remove_action( 'wp_head', '_wp_render_title_tag', 1);
add_action( 'wp_head', 'render_my_additional_head_content', 1);

推荐阅读