2013-10-03 46 views
0

我需要在特定帖子(帖子9597)上添加一些链接信息和简短脚本。我加入以下代码到我的主题的functions.php将信息添加到<head>的特定WordPress帖子

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.我在做什么错?

回答

0

您可能想在{}中添加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'); 
+1

我认为这是答案,OP是缺少开放/关闭如果标签 – gwillie

+0

感谢您的帮助enapupe! – hubs

相关问题