jquery - 在 Yoast 站点地图上是否有使 jQuery 出列的过滤器或操作?
问题描述
我从这个问题中添加了更多细节。
Yoast SEO page-sitemap.xml 是无效的 XML。显示错误Extra content at the end of the document
我发现 Yoast SEO无效,因为在声明page-sitemap.xml
之前插入了 jquery 脚本标签。<?xml>
像这样:
<script type='text/javascript' src='https://dev-intechrahealth.pantheonsite.io/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script>
<script type='text/javascript' src='https://dev-intechrahealth.pantheonsite.io/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>
<?xml version="1.0" encoding...
我不希望它们添加到站点地图文件中。我只是希望我的站点地图文件像这样开始:
<?xml version="1.0" encoding...
我发现的工作是添加一些 URL 检测代码来/wp-includes/script-loader.php
检查当前 URL 是否是站点地图,然后有条件地使用$scripts->add
. 像这样:
// jQuery
$url = $_SERVER["REQUEST_URI"];
$isItSitemap = strpos($url, 'sitemap');
if ($isItSitemap==false) {
$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.12.4' );
$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.12.4' );
$scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.4.1' );
}
但那是编辑核心,我不想这样做。我希望这发生在我的主题(Divi)functions.php
中,以便在我更新核心时保留。
所以我这样做了functions.php
:
/* Register jQuery but first detect if the Yoast SEO sitemap is rendering and dequeue script if so. This prevents an XML format error which is caused when <script> tags appear before the <?xml> declaration */
add_action( 'wp_enqueue_scripts', 'dequeue_jquery_for_sitemap', 10 );
function dequeue_jquery_for_sitemap() {
$url = $_SERVER["REQUEST_URI"];
$isItSitemap = strpos($url, 'sitemap');
if (!$isItSitemap==false) {
wp_dequeue_script( 'jquery' );
wp_dequeue_script( 'jquery-core' );
wp_dequeue_script( 'jquery-migrate' );
}
}
我什至也试过wp_deregister_script
:
wp_dequeue_script( 'jquery' );
wp_deregister_script( 'jquery' );
wp_dequeue_script( 'jquery-core' );
wp_deregister_script( 'jquery-core' );
wp_dequeue_script( 'jquery-migrate' );
wp_deregister_script( 'jquery-migrate' );
但是,这并不能解决问题。他们仍然出现在page-sitemap.xml
.
还有什么其他方法可以实现这一目标?或者我错过了什么?
解决方案
推荐阅读
- python - 如何处理这个异常?'错误:无法卸载'wrapt'。这是一个 distutils 安装的项目等。
- r - 将长格式分组数据转换为宽格式
- sql - 快速将列 NVARCHAR(4000) 更改为 NVARCHAR(260)
- jquery-ui - 向 jQuery UI 日期选择器添加第二个日期格式不起作用
- python - mfunction 和 elmul 有什么用?
- php - 如果第一次尝试在 PHP 中成功,如何防止第二次发送短信?
- css - 如何根据需要设计 ::before 语音气泡 V 形?
- c# - Httpclient 缓慢的内存增加问题 - 使用多线程的任务 Whenall
- azure-data-explorer - Azure 数据资源管理器 - 在用户定义函数的扩展运算符中使用标量输入作为列名参数
- python - 安装自己的项目作为依赖 | 模块名称问题