We have been contacted a few times asking how to hide he MashShare buttons from Timeline Express items on the timeline when using the Timeline Express – Post Types Add-On.
Since the MashShare buttons are added to all posts on the site, they are automatically added to the timeline items as well.
Removing MashShare Buttons on Timeline Posts
Luckily removing the share buttons from the posts on the timeline is quite simple. What we need to do is check what shortcode parameters are being used, and check for the existence of our post-type parameter. If this is being used in the shortcode, we can remove the share buttons altogether.
The following snippet of code can go right into your themes functions.php file. If you are unfamiliar with or uncomfortable editing your themes functions.php file, please take a look at our knowledge base article How do I add custom snippets to my theme without editing functions.php?.
/**
* Remove MashShare share buttons from Timeline Express post-type timelines.
*
* @author Code Parrots
*/
function remove_mashshare( $output, $pairs, $atts, $shortcode ) {
if ( ! isset( $atts['post-type'] ) && ! isset( $atts['post_type'] ) ) {
return;
}
add_filter( 'mashsb_the_content', '__return_null' );
}
add_filter( 'shortcode_atts_timeline-express', 'remove_mashshare', 10, 4 );
Once you’ve added the above snippet to either your themes functions.php file or using My Custom Functions you can save and reload your post type timeline to ensure that the share buttons are now gone.
Conditionally Hiding MashShare Buttons
If you have multiple timelines on different pages and want the share buttons to display on one but not the other this can also be achieved using conditionals. All we need to do is check what page we are on, and if we are on the page where we want the MashShare buttons hidden we filter them out.
The only thing you need to know for this is the page ID for the page (or pages) where you’d like the MashShare buttons hidden from. On each page edit screen in the URL you can see the ID next to `post=`. For example `/wp-admin/post.php?post=1234` the ID of that page would be 1234. So using that example we can filter out the MashShare buttons on page 1234 using the code below:
/**
* Unhook the MashShare buttons on page 1234 timeline.
*
* @author Code Parrots
*/
function remove_mashshare() {
global $post;
if ( is_admin() || 1234 !== $post->ID ) {
return;
}
add_filter( 'mashsb_the_content', '__return_null' );
}
add_action( 'wp_head', 'remove_mashshare' );
And there we have it. The MashShare buttons should now be hidden on page 1234 but visible on all other timelines.
Additional Help
If for some reason this does not work, or you need additional help – please don’t hesitate to reach out to us and we’d be more than happy to help out.