wordpress - 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.
解决方案
我最终使用其中一个钩子来删除标题,然后回显我想要添加到<head>
标签中的所有内容。
remove_action( 'wp_head', '_wp_render_title_tag', 1);
add_action( 'wp_head', 'render_my_additional_head_content', 1);
推荐阅读
- sql-server - LocalDB 需要 SQL Server 2016 LocalDB
- javascript - JavaScript中“++”(加空格加)的行为是什么?
- java - 尝试在 python:3.8-slim-buster 映像上安装 openjdk-8-jre 时生成错误
- excel - Excel SUMIFS() 使用大于/小于符号的字符串
- python - 新老客户数据透视表
- python - 如何基于数据类建立 ORM 模型
- angular - 角度 rxjs 间隔未订阅
- excel - 链接到 Access 的 Excel 文件;链接到 Power Query 的访问权限;刷新PowerQuery时弹出Excel文件
- windows - Psql 在尝试连接到 Postgresql 数据库时给出“SSLv3 警报握手错误”
- groovy - 使用 Groovy 捕获上个月的最后一天