• Not sure what’s going on here. We want to have this google adsense code show on all pages but the homepage. So to test I put this:

    <?php if (is_home()) {
    echo 'nothing';
    }
    else {
    echo '<script type="text/javascript"><!--
    google_ad_client = "removed";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "000000";
    google_color_bg = "FFFFFF";
    google_color_link = "FFFF66";
    google_color_text ="000000";
    google_color_url = "CAF99B";
    //--></script>
    <script type="text/javascript"
    src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    }
    ?>

    I’ve used conditionals before with no issues… and I am pretty sure it’s right, but no matter what it’s showing up across the whole site. I even tried changing is_home() to is_single() to see if it would display the “nothing” there, but no luck. I also tried instead of wrapping my echoes in “” regular quotes to use the single quotes (”) and escaping the google adsnese quotes with \ , but still shows across site….

    Thanks,
    Lindsey

Viewing 5 replies - 1 through 5 (of 5 total)
  • try it like this :

    <?php
    if (is_home()){
    echo ("hello world");
    }
    else { echo
    ("<script type="text/javascript"><!--
    google_ad_client = "removed";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "000000";
    google_color_bg = "FFFFFF";
    google_color_link = "FFFF66";
    google_color_text ="000000";
    google_color_url = "CAF99B";
    //--></script>
    <script type="text/javascript"
    src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>");
    }
    >?

    see if that brings it back it may need the single quotes – ill have to test it later if i remember, but that should be ok, just addind the (‘s

    phuckd: Your PHP won’t work. Single quotes need to be used, or you need to escape every single double quote within that Javascript in order to avoid ending the echo. Not to mention, there is no need for parenthesis when using echo.

    See: https://www.php.net/manual/en/function.echo.php

    lalindsey: There is nothing wrong with your PHP. I am not sure why it is not working. Perhaps you could paste the entire file at Pastecode.com for us.

    >>phuckd: Your PHP won’t work

    hence why i said it may need the single quotes.

    Well parenthesis still aren’t needed and it’s actually encouraged to not use them. ??

    Thread Starter Lindsey

    (@lalindsey)

    Hey guys,

    Thanks so much. I’ve pasted the entire sidebar code here: https://pastecode.com/6338

    If you want to see the entire site, it’s here: https://viralvoice.net

    It’s the adsense code in the right sidebar we want to not be shown on the homepage, but shown on every other.

    I don’t know if this matters or not, but it may — I’m using different code for the main index posts to get one/two posts for each of those categories to show under the right headings. I’ve pasted that code here: https://pastecode.com/6339

    Thanks again for any and all help,
    Lindsey

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditional Not Working’ is closed to new replies.