Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // genesis_entry_header action hook is used here because it is the one immediately above genesis_entry_content. Remember: Hook as late as possible.
- add_action( 'genesis_entry_header', 'sk_custom_post_image' );
- function sk_custom_post_image() {
- // if we are on portfolio CPT archive page and featured images are set to be shown on content archives in Genesis theme settings
- if ( is_post_type_archive( 'portfolio' ) && genesis_get_option( 'content_archive_thumbnail' ) ) {
- // remove the standard featured image output by Genesis per theme settings
- remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
- // add custom featured image output
- add_action( 'genesis_entry_content', 'sk_do_post_image', 8 );
- }
- }
- // Function to set the URL of featured image to value of a custom field, if present - otherwise to entry's permalink
- function sk_do_post_image() {
- // store value of "item_url" custom field into a variable named "$item_url"
- $item_url = esc_url( get_post_meta( get_the_ID(), 'item_url', true ) );
- // if "item_url" custom field is empty, store the permalink in the "$item_url" variable
- if ( empty( $item_url ) ) {
- $item_url = get_permalink();
- }
- $img = genesis_get_image( array(
- 'format' => 'html',
- 'size' => genesis_get_option( 'image_size' ),
- 'context' => 'archive',
- 'attr' => genesis_parse_attr( 'entry-image', array ( 'alt' => get_the_title() ) ),
- ) );
- if ( ! empty( $img ) ) {
- printf( '<a href="%s" aria-hidden="true">%s</a>', $item_url, $img );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement