自定义 <title>为 WordPress 网站上的所有页面和帖子添加标签 [英] Customize the <title> tag for all pages and posts on a WordPress website
问题描述
我一直在研究我遇到的一个问题,并遇到了这个讨论:
I have been researching a problem that I have and came across this discussion:
https://gtranslate.io/forum/how-not-translate-the-title-meta-tag-t4852.html
在那里提供的答案是使用这种 html 语法:
In there the answer provided is to use this html syntax:
<title class="notranslate">Example</title>
当前的问题是阻止 Google Translate 翻译
标签.我有一个 WordPress 网站:
The issue at hand is to prevent Google Translate from translating the <title>
tag. What I have is a WordPress website:
我不知道如何更改站点以将这种语法应用于我的帖子和页面上的所有 <title>
标签.我阅读了有关 wp_head()
的内容,但我迷路了.
I don't know how to go about changing the site to apply this syntax for all the <title>
tags on my posts and pages. I read up about wp_head()
but am getting lost.
感谢任何建议.
我正在使用的主题的 header.php
有以下代码:
The header.php
for the theme I am using has this code:
<?php wp_head(); ?>
<?php if ( get_option('google_analitic_code') ) : ?>
<?php echo get_option('google_analitic_code'); ?>
<?php endif; ?>
</head>
推荐答案
在function.php中添加下面的函数
Add Below function in function.php
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
在header.php中添加下面的代码,然后wp_head();
Add Below code in header.php befode wp_head();
<title class="notranslate"><?php bloginfo('name');?> | <?php wp_title();?></title>
希望这对你有用.
这篇关于自定义 <title>为 WordPress 网站上的所有页面和帖子添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!