Advertisement
srikat

Untitled

Feb 25th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. // genesis_entry_header action hook is used here because it is the one immediately above genesis_entry_content. Remember: Hook as late as possible.
  2. add_action( 'genesis_entry_header', 'sk_custom_post_image' );
  3. function sk_custom_post_image() {
  4.  
  5. // if we are on portfolio CPT archive page and featured images are set to be shown on content archives in Genesis theme settings
  6. if ( is_post_type_archive( 'portfolio' ) && genesis_get_option( 'content_archive_thumbnail' ) ) {
  7.  
  8. // remove the standard featured image output by Genesis per theme settings
  9. remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
  10.  
  11. // add custom featured image output
  12. add_action( 'genesis_entry_content', 'sk_do_post_image', 8 );
  13.  
  14. }
  15.  
  16. }
  17.  
  18. // Function to set the URL of featured image to value of a custom field, if present - otherwise to entry's permalink
  19. function sk_do_post_image() {
  20.  
  21. // store value of "item_url" custom field into a variable named "$item_url"
  22. $item_url = esc_url( get_post_meta( get_the_ID(), 'item_url', true ) );
  23.  
  24. // if "item_url" custom field is empty, store the permalink in the "$item_url" variable
  25. if ( empty( $item_url ) ) {
  26. $item_url = get_permalink();
  27. }
  28.  
  29. $img = genesis_get_image( array(
  30. 'format' => 'html',
  31. 'size' => genesis_get_option( 'image_size' ),
  32. 'context' => 'archive',
  33. 'attr' => genesis_parse_attr( 'entry-image', array ( 'alt' => get_the_title() ) ),
  34. ) );
  35.  
  36. if ( ! empty( $img ) ) {
  37. printf( '<a href="%s" aria-hidden="true">%s</a>', $item_url, $img );
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement