• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Need Custom Link URL for Featured Image (Post Thumbnail)

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: resolved

Tagged: featured image, post thumbnails

  • This topic has 7 replies, 2 voices, and was last updated 10 years, 3 months ago by nickthegeek.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • December 3, 2012 at 2:59 pm #3125
    derivative
    Member

    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' ) );
    }

    }

    }

    December 4, 2012 at 3:59 pm #3337
    nickthegeek
    Member

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

    December 4, 2012 at 4:18 pm #3344
    derivative
    Member

    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.

    December 4, 2012 at 4:19 pm #3345
    derivative
    Member

    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.

    December 4, 2012 at 4:27 pm #3347
    nickthegeek
    Member

    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.

    December 4, 2012 at 4:32 pm #3349
    derivative
    Member

    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?

    December 4, 2012 at 4:38 pm #3352
    derivative
    Member

    Solved!

    December 4, 2012 at 4:39 pm #3353
    nickthegeek
    Member

    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.

  • Author
    Posts
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.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble