[英]Change title in browser tab
I'm trying to change the title in browser tab for a child theme of twentytwelve.我正在尝试更改浏览器选项卡中的标题,以获得 2012 的子主题。 I wan't it to print out the same title on every page.
我不想在每一页上打印出相同的标题。 What the heck is happening?
到底发生了什么?
<?php
function im_awesome_title($title){
$title = "Im awesome!";
return $title;
}
add_filter( 'wp_title', 'im_awesome_title', 20 );
or some like this.或一些像这样。 script better put in the end of all php tags
脚本最好放在所有php标签的末尾
<?php
//set title
echo "<script>setTimeout(function(){var tts = document.getElementsByTagName(\"title\");if(tts.length > 0)tts[0].innerHTML=\"My title\"; else {var tt0 = document.createElement(\"TITLE\"); tt0.innerHTML = \"My title\"; document.head.appendChild(tt0);}}, 200);</script>";
?>
Your im_awesome_title($title) function will always return the value of $title when invoked.您的 im_awesome_title($title) 函数在调用时将始终返回 $title 的值。 To print this title on every page, you will need to call the function in the title meta tag of your pages.
要在每个页面上打印此标题,您需要在页面的标题元标记中调用该函数。 So it will look like this:
所以它看起来像这样:
<head>
<title><?php echo im_awesome_title($title); ?></title>
</head>
Of course your function expects an argument, so if you want the same title on every page, it's best to leave out the argument and simply set your $title variable to whatever page title that you want to use on all your pages.当然,您的函数需要一个参数,因此如果您希望在每个页面上使用相同的标题,最好省略该参数,只需将 $title 变量设置为您想要在所有页面上使用的任何页面标题。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.