Skip to content

Instantly share code, notes, and snippets.

@natebot
Last active May 26, 2017 01:34
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 natebot/8abdc949717ba1dc1ef2 to your computer and use it in GitHub Desktop.
Save natebot/8abdc949717ba1dc1ef2 to your computer and use it in GitHub Desktop.
Filtering SailThru Horizon meta tags
<?php
/**
* Add support for CoAuthors Plus in SailThru plugin
* @see http://getstarted.sailthru.com/wordpress-vip-plugin
*/
add_filter( 'sailthru_horizon_meta_tags', function( $horizon_tags, $post_object ){
// If we are using the CoAuthors Plus plugin then we need to replace the value of sailthru.author
// If there are multiple authors we use a comma seperated list
if( is_single() && class_exists( 'coauthors_plus' ) && class_exists( 'Sailthru_Horizon' ) ){
$coauthors = (array) wp_list_pluck ( (array) get_coauthors(), 'display_name' ); // array of authors
$author_string = implode( ', ', array_unique( $coauthors ) ); // comma-seperated string list of authors
if( $author_string )
$horizon_tags['sailthru.author'] = esc_attr( $author_string );
}
}, 10, 2 );
/**
* Customize the Sailthru.tags meta data to inlude the post's category and tag slugs
* @see http://getstarted.sailthru.com/wordpress-vip-plugin
*/
add_filter( 'sailthru_horizon_meta_tags', function( $horizon_tags, $post_object ){
// Replace Sailthru.tags with the posts of tag and category slugs
$tags = (array) wp_list_pluck( (array) get_the_tags(), 'slug' );
$cats = (array) wp_list_pluck( (array) get_the_category(), 'slug' );
// cats and tags can have matching slugs so we merge and remove redundent slugs
$tags_array = array_filter( array_unique( array_merge( $cats, $tags ) ) );
$tag_string = implode( ', ', $tags_array );
if( $tag_string ) {
$horizon_tags['sailthru.tags'] = esc_attr( $tag_string );
}
return $horizon_tags;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment