Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfmeier/8cbe9895612a9dff5a95 to your computer and use it in GitHub Desktop.
Save rfmeier/8cbe9895612a9dff5a95 to your computer and use it in GitHub Desktop.
Remove post format anchor element and silence image alt attribute
<?php
// remove the default Genesis core callbacks
remove_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 );
remove_action( 'genesis_before_post_title', 'genesis_do_post_format_image' );
// add custom callbacks
add_action( 'genesis_entry_header', 'custom_do_post_format_image', 4 );
add_action( 'genesis_before_post_title', 'custom_do_post_format_image' );
/**
* Add a post format icon.
*
* ** Modified Genesis core genesis_do_post_format_image() function. **
*
* Adds an image, corresponding to the post format, before the post title.
*
* @return null Return early if post formats are not supported, or `genesis-post-format-images` is not supported
*/
function custom_do_post_format_image() {
// if on a page, return (do not display icon)
if( is_page() )
return;
//* Do nothing if post formats aren't supported
if ( ! current_theme_supports( 'post-formats' ) || ! current_theme_supports( 'genesis-post-format-images' ) )
return;
//* Get post format
$post_format = get_post_format();
//* If post format is set, look for post format image
if ( $post_format && file_exists( sprintf( '%s/images/post-formats/%s.png', CHILD_DIR, $post_format ) ) )
printf( '<img src="%s" class="post-format-image" alt="" />', sprintf( '%s/images/post-formats/%s.png', CHILD_URL, $post_format ) );
//* Else, look for the default post format image
elseif ( file_exists( sprintf( '%s/images/post-formats/default.png', CHILD_DIR ) ) )
printf( '<img src="%s/images/post-formats/default.png" class="post-format-image" alt="" />', CHILD_URL );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment