php - 如何在 wp_head() 中删除没有类或 id 的内联 css
问题描述
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style media="all">
Bounce of code
</style>
<link rel='stylesheet' id='...' href='...' media='all'/>
<script>...</script>
...
</head>
我想删除<style media="all"> Bounce of code </style>
头部的一部分。它在 wp_head() 中。有没有办法做到这一点?
提前致谢。
解决方案
除了调试整个网站及其主题/插件之外,另一种解决方案是简单地将其添加到主题的末尾functions.php
:
function start_wp_head_buffer()
{
ob_start();
}
function end_wp_head_buffer()
{
$in = ob_get_clean();
$in = preg_replace('/' . preg_quote('<style media="all">') . '\s*' . preg_quote('Bounce of code') . '\s*' . preg_quote('</style>', '/') . '/s', '', $in);
echo $in;
}
add_action('wp_head', 'start_wp_head_buffer', 0);
add_action('wp_head', 'end_wp_head_buffer', PHP_INT_MAX);
推荐阅读
- javascript - 我们可以为移动视图实现带有触摸事件的 Drag n Drop 吗?
- javascript - 什么相当于打字稿中的java interface.class
- linux - 用于 linux 的“touch”更新文件时间戳的 Windows 等效命令
- python - 以管理员身份运行 python 脚本时创建的两个 tkinter 窗口实例
- c - 插座。设置 sockaddr_in 结构的 s_addr 字段
- jmeter - Jmeter-5.0:RPS(每秒请求数)和 TPS(每秒事务数)是否相同?
- laravel-5 - 如何使用包 bschmitt/laravel-amqp 在 RabbitMq Laravel 中使用消息
- terraform - GCP terraform 提供程序 - 可能的文档错误?
- c# - 文本框 textchange 事件以单击 datagridview 中的复选框
- python - 如何在 macbook 中为 C++ 库安装 Python API