Need Custom Link URL for Featured Image (Post Thumbnail)

Community Forums Forums Design Tips and Tricks Need Custom Link URL for Featured Image (Post Thumbnail)

This topic is: resolved

This topic contains 7 replies, has 2 voices, and was last updated by  nickthegeek 1 year, 8 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3125

    derivative
    Participant

    I am having trouble coding this to function properly.

    I have a site where I need to display the post thumbnail or featured images below the title (which works fine). On the Single Posts I need to have the featured image link to a custom URL as set by a custom field that I made called featured_image_offer_url

     

    Here is the code that I have so far (the image only returns the post URL in the a href= ( I see the get_permalink()))

     

    /** Add custom field below post title */
    add_action( ‘genesis_after_post_title’, ‘luscious_post_image’, 8 );
    function luscious_post_image() {

    if ( is_page() )
    return;

    if(is_home()) {

    if ( $image = genesis_get_image( ‘format=url&size=post-photo’ ) ) {
    printf( ‘<a href=”%s” rel=”bookmark”><img class=”post-photo” src=”%s” alt=”%s” /></a>’, get_permalink(), $image, the_title_attribute( ‘echo=0′ ) );
    }
    }
    /** Single post featured image */

    if(is_single()) {

    if ( $image = genesis_get_image( ‘format=url&size=post-photo’ ) ) {

    printf( ‘<a href=”%s”><img class=”post-photo” src=”%s” alt=”%s” /></a>’, get_permalink(), $image, the_title_attribute( ‘echo=0′ ) );
    }

    }

    }

    #3337

    nickthegeek
    Keymaster
    Post count: 751

    the second time you use get_permalink() you should be using genesis_get_custom_field(‘featured_image_offer_url’)

    #3344

    derivative
    Participant

    Unfortunately it still doesn’t work:

    The custom field is featured_image_offer_url and the URL is put in as plain text (do I need to put in as HTML)

    The featured image is still linking to the post itself, not the custom URL.

    Do I need to register the custom field some other way? I am using the advanced custom fields plugin to create it.

    #3345

    derivative
    Participant

    Unfortunately it still doesn’t work:

    The custom field is featured_image_offer_url and the URL is put in as plain text (do I need to put in as HTML)

    The featured image is still linking to the post itself, not the custom URL.

    Do I need to register the custom field some other way? I am using the advanced custom fields plugin to create it.

    #3347

    nickthegeek
    Keymaster
    Post count: 751

    If you are using the ACF plugin check with them to see the recommended function to retrieve custom field data. They have their own function for that.

    #3349

    derivative
    Participant

    If I wanted to ditch the ACF plugin and use the genesis function to retrieve the URL as you stated, how would I register the custom field?

    #3352

    derivative
    Participant

    Solved!

    #3353

    nickthegeek
    Keymaster
    Post count: 751

    you could just add a custom field. No need for anything fancy. If oyu don’t see the custom field meta box click “screen options” and make sure that it is enabled there.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Need Custom Link URL for Featured Image (Post Thumbnail)’ is closed to new replies.