Community Forums › Forums › Design Tips and Tricks › Need Custom Link URL for Featured Image (Post Thumbnail)
Tagged: featured image, post thumbnails
This topic contains 7 replies, has 2 voices, and was last updated by nickthegeek 5 months, 2 weeks ago.
-
AuthorPosts
-
December 3, 2012 at 2:59 pm #3125
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 #3337the 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 #3344Unfortunately 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 #3345Unfortunately 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 #3347If 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 #3349If 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 #3352Solved!
December 4, 2012 at 4:39 pm #3353you 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.
-
AuthorPosts
The topic ‘Need Custom Link URL for Featured Image (Post Thumbnail)’ is closed to new replies.