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?

  • 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, 2013 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, 2013 at 5:18

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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