Make Custom Field a link

This topic contains 2 replies, has 2 voices, and was last updated by  Chris Hirst 8 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #25723

    Stephen, I have edited the event-meta-event-single.php file to include a couple of custom fields in the header. All works well, but one of then is a web address and I do not know how to format that into a link.

    I notice on the FES there is already a field in there for website, but it does not seem to appear anywhere when using that form. That is why I have added a custom field for it.

    Anyway, the line of code with the link I need is below. If you could help me change that to a link that would be great thanks

    <li><?php   
    if ( get_post_meta( get_the_ID(), 'eo_events_website', true ) ) {
         printf( '<strong>Website:</strong> %s',  esc_html( get_post_meta( get_the_ID(), 'eo_events_website', true ) ));
    } 
    ?></li>
    

    Thanks Chris

    Chris Hirst
    #25727

    Try:

    <?php
    if ( get_post_meta( get_the_ID(), 'eo_events_website', true ) ) {
        printf( 
           'Website: <a href="%s">%s</a>',
           esc_url( get_post_meta( get_the_ID(), 'eo_events_website', true ) ),
           esc_html( get_post_meta( get_the_ID(), 'eo_events_website', true ) )
        );
    }
    ?>
    
    Stephen Harris
    #25728

    That works just fine thank you

    Chris Hirst
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.