Support » Fixing WordPress » Issue with Conditional Tag

  • Resolved nicolecdenton

    (@nicolecdenton)


    I’m trying to place a conditional tag in my header, to show one ad code on the homepage and another ad code on the rest of the site. I can get the homepage code to work alone, but when I add the “else,” I get a syntax error. Here’s the code I’m trying to use…

    <?php if (is_home()):
            echo '<div id='div-gpt-ad-1388971293846-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_HP', [728, 90], 'div-gpt-ad-1388971293846-0');
    </script></div>';
    else:
    echo '<div id='div-gpt-ad-1388971354741-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_ROS', [728, 90], 'div-gpt-ad-1388971354741-0');
    </script></div>';
    endif;
    ?>

    Does anyone know what I’m doing wrong?

    My site is http://www.theplungeproject.com.

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

    (@alchymyth)

    Forum Moderator

    caused by the single quotes in the echo string in the else section;

    possibly try (untested):

    else:
    echo '<div id="div-gpt-ad-1388971354741-0">
    <script type="text/javascript" src="http://www.googletagservices.com/tag/js/gpt.js" >
    googletag.pubads().display("/39950040/PlungeProject_ROS", [728, 90], "div-gpt-ad-1388971354741-0");
    </script></div>';
    endif;

    or:

    else:
    echo "<div id='div-gpt-ad-1388971354741-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_ROS', [728, 90], 'div-gpt-ad-1388971354741-0');
    </script></div>";
    endif;

    Tried both options, and I still get the error…

    “Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/cproduct/public_html/theplungeproject.com/wp-content/themes/Adelle/header.php on line 44”

    Michael

    (@alchymyth)

    Forum Moderator

    I just see you have the same issue with the first part;

    try:

    <?php if (is_home()):
            echo "<div id='div-gpt-ad-1388971293846-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_HP', [728, 90], 'div-gpt-ad-1388971293846-0');
    </script></div>";
    else:
    echo "<div id='div-gpt-ad-1388971354741-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_ROS', [728, 90], 'div-gpt-ad-1388971354741-0');
    </script></div>";
    endif;
    ?>

    or:

    <?php if (is_home()): ?>
            <div id='div-gpt-ad-1388971293846-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_HP', [728, 90], 'div-gpt-ad-1388971293846-0');
    </script></div>
    <?php else: ?>
    <div id='div-gpt-ad-1388971354741-0'>
    <script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js' >
    googletag.pubads().display('/39950040/PlungeProject_ROS', [728, 90], 'div-gpt-ad-1388971354741-0');
    </script></div>
    <?php endif;
    ?>

    if this does not work, please use the pastebin to post the full code – http://codex.wordpress.org/Forum_Welcome#Posting_Code

    It worked! Thank you so much 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Issue with Conditional Tag’ is closed to new replies.