I am trying to publish custom fields created using the plugin "Advanced Custom fields". I am able to display them on posts and custom post types as raw output. But I want to wrap html around the output.

Ex: Field-1(field name is 'the_one'): I want to publish any content like Text or Date with the format I want.

<?php if( get_field('the_one') != '' ) : ?>
        <span class=the_one field1"><a href="<?php echo get_field('the_one'); ?>"><?php _e( '<b data-icon="info" class="inner-content">Content</b>', $post_id ); ?></a></span>

Field-2 (field name is 'the_link'): I want the URLs for website urls be published converting to links

<?php if( get_field('the_link') != '' ) : ?>
    <span class=the_link field2"><a href="<?php echo get_field('the_one'); ?>"><?php _e( '<b data-icon="web" class="inner-content">Special Category</b>', $post_id ); ?></a></span>
<?php endif; ?>

Could any one help me with this?


Update: I have no success creating custom fields by own. So tried to use ACF again. Here is the loop.php code- http://pastebin.com/7UE2izdg. Custom fields are in the lines 58 and 59.

1 Answer 1


There are many things in your code, I don't know why you implemented like that. In my view the corrected code should be:

if ( get_post_meta( $post->ID, 'the_link', true ) != '' ) : ?>
    <span class="the_one field1">
        <a href="<?php echo esc_attr(get_post_meta( $post->ID, 'the_link', true )); ?>">
            <b data-icon="info" class="inner-content"><?php echo _e( 'Content', 'theme-text-domain' ); ?></b>

Rather than any ACF command, I'd like to go with WordPress default code get_post_meta(), and it's a fine one. I found some syntax error, where you started a span class without a double quote. _e() is a translation parameter that demands a theme text domain, NOT a post_id.

<?php _e( 'my text', 'text-domain' ); ?>

It's just a simple string thing. So you can leave it there and can embrace it with any kind of HTML outside the PHP.

And another conceptual thing is:
ACF is just a nice plugin to let the user do nice things with Custom Fields. But in core Custom Fields are all same, whether by plugin or core codes. They are the Post Meta. So whether checking they exists or not, or echoing them is always same as WordPress do, and it's the get_post_meta().

  • 2
    Few things. Don't put variable if you don't use it ($single=true in get_post_meta calls). Also you should escape attributes... User can input anything in meta field and it would be good to be sure, that it won't break the page... Dec 2, 2013 at 6:46
  • Thanks @KrzysiekDróżdż. I'll keep in mind in next move. :) Dec 2, 2013 at 7:02
  • Hello @MayeenulIslam, I tried to use the code given and I got an issue. The page content is broken and I can't see the post content(showing everything blank). I think I done something wrong on my end as I never created custom fields myself by scratch. I have updated the original post with the copy of loop.php and ACF's fields I created. Can you help me with that?
    – Netizen
    Dec 11, 2013 at 8:43
  • Please confirm that without my code, your page is working properly, except the custom field thing - is that right? Dec 11, 2013 at 14:39
  • @MayeenulIslam Yes! You are right. Without the code, the page appears fine.
    – Netizen
    Dec 15, 2013 at 4:52

Your Answer

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

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