How to add PHP code inside PHP code?

For example (in my case) here’s some code,

<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );
    woo_post_meta();
?>

Now I would like to place the following PHP code so that it’s output before woo_post_meta();:

Read More
    <?php if (is_single()) : ?>
    <div class="testb"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; ?>

If I have to show it literally, the code would be like this:

<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );

    <?php if (is_single()) : ?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; ?>

    woo_post_meta();
?>

Apparently that’s not the right way of doing it. So, how do I do it?

Related posts

Leave a Reply

4 comments

  1. Just have one set of tags:

    <?php
        woo_post_inside_before();   
        if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
            woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
        the_title( $title_before, $title_after );
    
        if (is_single()){
    ?>
        <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php
        }
    
        woo_post_meta();
    ?>
    
  2. There’s many ways to do it. Here’s one.

    <?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
    {
         woo_image(   'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbna il '.$woo_options['woo_thumb_align'] );
    }
    the_title( $title_before, $title_after );
    ?>
    <?php if (is_single()) : ?>
        <div class="testthisad"><img src="http://whatthenerd.com/what/wp-     content/themes/canvas/300.jpg" alt="test Ad" /></div>
        <?php endif; ?>
    
    <?php  woo_post_meta(); ?>
    
  3. This will do what you want (not tested):

    <?php
        woo_post_inside_before();   
        if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
            woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
        the_title( $title_before, $title_after );
    
        if (is_single()) : ? echo "[HTML code handling slashes]" /></div>;
    
        woo_post_meta();
    ?>
    

    http://www.w3schools.com/php/php_if_else.asp?output=print

  4. You can do

    <?php
    // Code...
    eval('my code as a string');
    

    Have in mind though that’s crazy dangerous.

    But in your case I think you can just do

    <?php
        woo_post_inside_before();   
        if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
            woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
        the_title( $title_before, $title_after );
    
        if (is_single()) : ?>
        <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
        <?php endif; 
        woo_post_meta();
    ?>