WordPress.org

Ready to get started?Download WordPress

Forums

Conditional Not Working (6 posts)

  1. CSSgirl
    Member
    Posted 7 years ago #

    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="http://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

  2. phuckd
    Member
    Posted 7 years ago #

    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="http://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

  3. 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: http://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.

  4. phuckd
    Member
    Posted 7 years ago #

    >>phuckd: Your PHP won't work

    hence why i said it may need the single quotes.

  5. Well parenthesis still aren't needed and it's actually encouraged to not use them. ;)

  6. CSSgirl
    Member
    Posted 7 years ago #

    Hey guys,

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

    If you want to see the entire site, it's here: http://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: http://pastecode.com/6339

    Thanks again for any and all help,
    Lindsey

Topic Closed

This topic has been closed to new replies.

About this Topic