Title: How to code php within php?
Last modified: August 19, 2016

---

# How to code php within php?

 *  Resolved [jemaverick](https://wordpress.org/support/users/jemaverick/)
 * (@jemaverick)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/how-to-code-php-within-php/)
 * Hi there. My challenge is this. I’m designing a theme that displays pics beside
   each post excerpt on the index, tag, category, etc. pages, and am wanting to 
   make the path to the a default image generic so that users of the theme don’t
   need to mess around in the code – bam, it’s there for you use without worrying
   about it. The problem for me is that I’m a bit of a hack, and my php skill set
   isn’t worth much of a hoot. I don’t even find it intuitive. I’ve tried messing
   around with TEMPLATEPATH, bloginfo(‘stylesheet_directory’); and the like to no
   avail, so I need a bit of a prod in the right direction. How do I place php within
   php?
 * Ok, the working code I have got in the theme is this:
 *     ```
       // if there's not a thumbnail
       else { echo '<img src="http://www.mysite.com/wp-content/themes/supafly/images/default.png" alt="Default Text Goes Here" title="Default Text Goes Here"/>'; } ?></div>
       ```
   
 * Not really useful to anybody else who hasn’t got [http://www.mysite.com/](http://www.mysite.com/)
   as their domain.
 * I would really like to have code that reflects:
 *     ```
       // if there's not a thumbnail
       else { echo '<img src="PATH TO STYLESHEET DIRECTORY/images/default.png" alt="Default Text Goes Here" title="Default Text Goes Here"/>'; } ?></div>
       ```
   
 * Can anybody out there help me with meeting this challenge?
 * Cheers,
 * J.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/how-to-code-php-within-php/#post-1242530)
 *     ```
       // if there's not a thumbnail
       else { ?>
       <img src="<?php bloginfo('template_directory'); ?>/images/default.png" alt="Default Text Goes Here" title="Default Text Goes Here" />
       <?php } ?>
       </div>
       ```
   
 * It could also be written as
    `echo '<img src="', bloginfo('template_directory'),'/
   images/default.png" alt="Default Text Goes Here" title="Default Text Goes Here"/
   >';` (think I got that right)
 *  Thread Starter [jemaverick](https://wordpress.org/support/users/jemaverick/)
 * (@jemaverick)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/how-to-code-php-within-php/#post-1242824)
 * Thank you so much stvwolf. That worked perfectly. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to code php within php?’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [jemaverick](https://wordpress.org/support/users/jemaverick/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/how-to-code-php-within-php/#post-1242824)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
