WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Issue with Conditional Tag (5 posts)

  1. nicolecdenton
    Member
    Posted 6 months ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 6 months ago #

    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;
  3. nicolecdenton
    Member
    Posted 6 months ago #

    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"

  4. alchymyth
    Forum Moderator
    Posted 6 months ago #

    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

  5. nicolecdenton
    Member
    Posted 6 months ago #

    It worked! Thank you so much :)

Reply

You must log in to post.

About this Topic

Tags