Last active
January 4, 2016 05:09
-
-
Save robneu/8573583 to your computer and use it in GitHub Desktop.
The default Genesis post info can be tweaked for a bit of extra SEO goodness. This will change your posts publish date to use the last-updated date instead. It also allows you to select a custom author page rather than using the standard post archive. This part is optional and doesn't affect the post date at all.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Some tweaks to the Genesis post info for SEO purposes. | |
* | |
* This set of functions are designed to change the output of the Genesis post info | |
* to reflect the date a post was updated rather than the date it was published. A | |
* function to set a custom author page is also included and is entirely optional. | |
* | |
* @author FAT Media, LLC | |
* @link http://auditwp.com/genesis-post-info-seo/ | |
*/ | |
add_filter( 'genesis_attr_entry-time', 'prefix_attributes_entry_time' ); | |
/** | |
* Filter attributes to show the modified timestamp for the entry. | |
* | |
* @param array $attributes Existing attributes. | |
* @return array Amended attributes. | |
*/ | |
function prefix_attributes_entry_time( $attributes ) { | |
$attributes['itemprop'] = 'dateModified'; | |
$attributes['datetime'] = get_the_modified_time( 'c' ); | |
return $attributes; | |
} | |
add_filter( 'genesis_post_date_shortcode', 'prefix_post_date_filter' ); | |
/** | |
* Filter the output of the post date to show the modified date. | |
* | |
* @param array $output Existing output. | |
* @return string $output Modifed output. | |
*/ | |
function prefix_post_date_filter( $output ) { | |
$display = get_the_modified_date(); | |
$output = sprintf( '<time %s>', genesis_attr( 'entry-time' ) ) . $atts['before'] . $atts['label'] . $display . $atts['after'] . '</time>'; | |
return $output; | |
} | |
add_filter( 'genesis_post_author_link_shortcode', 'prefix_custom_author_link' ); | |
/** | |
* Filter the output of the post link to resolve to a custom URL. | |
* | |
* @param array $output Existing output. | |
* @return string $output Modifed output. | |
*/ | |
function prefix_custom_author_link( $output ) { | |
// If we're not showing a post by you, do nothing. | |
if ( get_the_author() != 'Your Name' ) { | |
return $output; | |
} | |
// Set the URL to your "About" page. | |
$url = get_permalink( 15 ); | |
$author = get_the_author(); | |
$output = sprintf( '<span %s>', genesis_attr( 'entry-author' ) ); | |
$output .= $atts['before']; | |
$output .= sprintf( '<a href="%s" %s>', $url, genesis_attr( 'entry-author-link' ) ); | |
$output .= sprintf( '<span %s>', genesis_attr( 'entry-author-name' ) ); | |
$output .= esc_html( $author ); | |
$output .= '</span></a>' . $atts['after'] . '</span>'; | |
return $output; | |
} | |
add_filter( 'genesis_post_info', 'prefix_post_info_filter' ); | |
/** | |
* Filter the output of the post info to remove links to post comments in archives. | |
* | |
* @param array $post_info Existing post info. | |
* @return string $post_info Modifed post info. | |
*/ | |
function prefix_post_info_filter( $post_info ) { | |
if ( is_page() ) { | |
return; | |
} | |
$post_info = 'Last Updated on [post_date] // Written by [post_author_link] [post_edit]'; | |
if ( is_singular( 'post' ) ) { | |
$post_info = 'Last Updated on [post_date] // Written by [post_author_link] [post_comments] [post_edit]'; | |
} | |
return $post_info; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment