• 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

Add an external URL to a featured image in the Genesis Featured Post widget

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 › Add an external URL to a featured image in the Genesis Featured Post widget

This topic is: not resolved

Tagged: featured image, genesis featured post widget, URL

  • This topic has 2 replies, 3 voices, and was last updated 3 years ago by Anita.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • January 16, 2020 at 4:59 am #495972
    Fiona
    Member

    Hi
    I am building a website for a client using the Genesis theme. The client’s organisation has a number of sponsors, and the client wants to display a small ad or logo with a link to their websites in the sidebar. There are Gold, Silver and Bronze sponsorship levels. In order to display these in a random order I was thinking of creating each sponsor as a post with their ad or logo as the featured image and then use the Genesis Featured Post widget with only the featured image checked. However my php skills are very basic and I'm struggling to find the right code to add the URL link to the featured image.
    I found some code online that enables such a link to be added to the featured image in a post or page by creating a custom field "ExternalUrl":

    add_filter('post_thumbnail_html','add_external_link_on_page_post_thumbnail',1);
        function add_external_link_on_page_post_thumbnail( $html ) {
        if( is_singular ) {
               global $post; 
                $name = get_post_meta($post->ID, 'ExternalUrl', true);
                if( $name ) {
                        $html = '<a href="' . ( $name ) . '" target="_blank" >' . $html . '</a>';
                }
        }
        return $html;
        }

    I have created the custom field and have tried adapting the code:

    add_filter('post_thumbnail_html','add_external_link_on_page_post_thumbnail',1);
        function add_external_link_on_page_post_thumbnail( $html ) {
        if( is_active_sidebar ) {
               global $post; 
                $name = get_post_meta($post->ID, 'ExternalUrl', true);
                if( $name ) {
                        $html = '<a href="' . ( $name ) . '" target="_blank" >' . $html . '</a>';
                }
        }
        return $html;
        }

    However this isn't working. Does anyone have any suggestions?

    http://staging.sportsshots.org.uk
    January 16, 2020 at 7:33 am #495973
    Victor Font
    Moderator

    Seems like a lot of extra effort to achieve a goal that can be easily accomplished with a custom HTML widget or image widget.

    The reason your approach isn't working is because the post_thumbnail_html filter is not used by the Genesis Featured Post widget. The WordPress function that uses that filter, get_the_post_thumbnail(), is not called anywhere in the Genesis framework.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 16, 2020 at 1:28 pm #495974
    Anita
    Keymaster

    Sounds like you just need to use Genesis Featured Page Advanced. No extra code needed - https://wordpress.org/plugins/genesis-featured-page-advanced/.


    Love coffee, chocolate and my Bella!

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and 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