WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After read a lot in a lot of sites, finally I was able to do something similar what I was trying (read a lot because I don't know code at all), is the follow:

I want to use a background image for my custom fields.

I did this in single.php:

<div class="post-meta">
             <?php $firstCF = get_post_meta($post->ID, 'firstCF', true);
if ($dorigen) { ?>
             My text: <?php echo $firstCF; ?></br></br>
  <?php } 
else { ?>  </h3><?php } ?>
             <?php $secondCF = get_post_meta($post->ID, 'secondCF', true);
if ($dorigen) { ?>
             Other Text: <?php echo $secondCF; ?></br></br>
  <?php } 
else { ?> </h3><?php } ?>

.post-meta {
    text-shadow: 0 1px 0 #252525;
    color: #f2f6d7;
    padding-top: 22px;
    padding-left: 190px;
    float: left;
    height: 150px;
    width: 600px;
    background-image: url(../images/fondo-campos-personalizados.gif);
    background-repeat: no-repeat;   

The problem is that will not use always firstCF and/or secondCF in all my post and the background image always is there.

Another Q: I use h3, but when I see source in browser I can't find </h3>, but the size and characteristics of the text are really those of my css h3. I don't know if Google and others, will understand that they are really h3.

Is there a way to do something like this?

share|improve this question
I use that code becouse I use Disqus and Post Rating plugins and those use Custom Fields too. If I use for example: if( the_meta() ) : <div class="cfield"> <?php the_meta(); sigle.php show info about those plugins.. – mdroca Feb 27 '13 at 21:31
I couldn't find a better title for this Question, as it is really not clear what the Custom Field has to do with the background-image... Also, you tagged the Q with Advanced Custom Fields, what does it has to do with this? :::: Please, add more details to the Q itself, you are free to edit it whenever needed. – brasofilo Feb 28 '13 at 5:18

I don't know what $dorigen is - but you can't find your </h3> because of your if/else condition. I don't see why the else is needed at all. Replace

else { ?> </h3><?php } ?>



in both places it is used.

That said, if you only want to show the entire post-meta div when the meta values are set, then you should do something like this (untested):

$firstCF = get_post_meta( $post->ID, 'firstCF', true );
$secondCF = get_post_meta( $post->ID, 'secondCF', true );
if ( $firstCF || $secondCF ) {
    <div class="post-meta">
    <?php if ( $dorigen ) { ?>
                My text: <?php echo $firstCF; ?></br></br>
    <?php } ?>  </h3>
    <?php if ( $dorigen ) { ?>
                Other Text: <?php echo $secondCF; ?></br></br>
    <?php } ?> </h3>

I left the dorigen stuff in even though I don't know what it's for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.