Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active August 29, 2015 14:14
Show Gist options
  • Save srikat/c00e86cdfb9e068b576a to your computer and use it in GitHub Desktop.
Save srikat/c00e86cdfb9e068b576a to your computer and use it in GitHub Desktop.
How to add a link to author's Twitter page in post info in Genesis. http://sridharkatakam.com/add-link-authors-twitter-page-post-info-genesis/
//* Enqueue Dashicons
add_action( 'wp_enqueue_scripts', 'enqueue_dashicons' );
function enqueue_dashicons() {
wp_enqueue_style( 'dashicons' );
}
//* Add Twitter field in User Profile page in WP admin
function my_new_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = 'Twitter (w/o the @)';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'my_new_contactmethods', 10, 1 );
//* Create [twitter_link] shortcode
add_shortcode( 'twitter_link', 'gamajo_twitter_link_shortcode' );
function gamajo_twitter_link_shortcode() {
$twitter_handle = ltrim( get_the_author_meta( 'twitter' ), '@' );
if ( empty( $twitter_handle ) ) {
return '';
}
return sprintf(
'<span class="twitter"><a href="%s" target="_blank">@%s</a></span>',
esc_url( 'https://twitter.com/' . $twitter_handle ),
$twitter_handle
);
}
//* Customize entry meta in the entry header
add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter( $post_info ) {
if ( is_singular( 'post' ) ) {
$post_info = 'by [post_author_posts_link] on [post_date] [twitter_link] [post_edit]';
}
return $post_info;
}
/* Twitter link in post info
--------------------------------------------- */
p.entry-meta {
font-style: italic;
}
.twitter {
position: relative;
margin-left: 10px;
}
.twitter:before {
content: "\f301";
display: inline-block;
-webkit-font-smoothing: antialiased;
font: normal 20px/1 'dashicons';
vertical-align: middle;
/*position: absolute;
left: -23px;
top: 2px;*/
color: #00abf0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment