我需要在特定帖子(帖子 9597)上添加一些链接信息和简短脚本。我正在将以下代码添加到我的主题函数中.php
function chromeextension_head() {
if(is_single( '9597' ))
?>
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/pknhdfeakbecfgahlbdfnjfjgbkgllfo">
<script>
function ExtInstall() {
if (chrome.app.isInstalled)
alert("already installed!");
else
chrome.webstore.install();
}
</script>
<?php
}
add_action( 'wp_head', 'chromeextension_head' );
问题是现在代码显示在所有帖子和页面上,而不仅仅是帖子 9597。我做错了什么?
您可能
希望在 {} 中添加 html 代码。
function chromeextension_head() {
if(is_single( '9597' )){
?>
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/pknhdfeakbecfgahlbdfnjfjgbkgllfo">
<script>
function ExtInstall() {
if (chrome.app.isInstalled)
alert("already installed!");
else
chrome.webstore.install();
}
</script>
<?php
} }
add_action( 'wp_head', 'chromeextension_head' );