Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add an external URL to a featured image in the Genesis Featured Post widget
Tagged: featured image, genesis featured post widget, URL
- This topic has 2 replies, 3 voices, and was last updated 6 years ago by
AnitaC.
-
AuthorPosts
-
January 16, 2020 at 4:59 am #495972
Fiona
MemberHi
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.ukJanuary 16, 2020 at 7:33 am #495973Victor Font
ModeratorSeems 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 #495974AnitaC
KeymasterSounds like you just need to use Genesis Featured Page Advanced. No extra code needed - https://wordpress.org/plugins/genesis-featured-page-advanced/.
Need help with customization or troubleshooting? Reach out to me.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.