[英]WooCommerce - Change page title when tab is not active
I am looking for function for WooCommerce which change meta title text in non-active tab.我正在寻找 WooCommerce 的 function 来更改非活动选项卡中的元标题文本。 Anybody know how can I do it?
有人知道我该怎么做吗? I find this JS code but it does not work in themes function.php file:
我找到了这个 JS 代码,但它在主题 function.php 文件中不起作用:
$(function() {
var message = "Don't forget us";
var original;
$(window).focus(function() {
if (original) {
document.title = original;
}
}).blur(function() {
var title = $('title').text();
if (title != message) {
original = title;
}
document.title = message;
});
});
You can put that script into a tag <script></script>
in the footer.php file wich should be located in your theme (don't forget to actually duplicate this file inside your child theme)您可以将该脚本放入页脚中的标签
<script></script>
中。php 文件应该位于您的主题中(不要忘记在您的子主题中实际复制此文件)
EDIT: Also make sur to have JQuery in your frontend编辑:也让 sur 在你的前端有 JQuery
The following goes into functions.php
以下进入
functions.php
add_action('wp_head', function () {
?>
<script>
(function () {
var message = "Don't forget us"
var original
jQuery(window).on("focus", function () {
if (original) {
document.title = original
}
}).on("blur", function () {
var title = jQuery("title").text()
if (title != message) {
original = title
}
document.title = message
})
})()
</script>
<?php
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.