• I need to add some link information and a short script to my <head> on a specific post (post 9597). I am adding the following code to my themes functions.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' );

    The problem is that now the code shows up on all posts and pages, not just post 9597. What am I doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Instead of

    if(is_single( '9597' ))

    try

    if(is_single () && $post->ID == 9597))

    I haven’t tested that, but it should work better.

    Thread Starter artifacting

    (@artifacting)

    Sorry catacaustic, that didn’t work either.

    Anybody have any other ideas?

    If that doesn’t work try this for debugging ..

    if(is_single () & $ post-> ID == 9597) {
        // Your code here...
    }
    else {
        echo "Single: '".is_single ()."', ID: '".$ post-> ID."'";
    }

    That will tell you WHY your not getting what you expect. That’s basic debugging. You’ll need to kearn just how useful that is. When something isn’t doing what it should find out exactly what is wrong.

    Thread Starter artifacting

    (@artifacting)

    I needed to add the html code within {}. Like this:

    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' );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add info to the head of a specific post’ is closed to new replies.