Moving Jetpack Sharedaddy Links Outside The Content With Genesis
Since switching to the Genesis Framework, I have been investigating different ways to easily add and remove content with Genesis. I quickly learned how easy it is to alter content and structure with Genesis.
I currently use Sharedaddy links that come packaged with Jetpack. By default, these share links are appended before or after the post content. I thought I would share how I moved the Sharedaddy links after my content by utilizing the Genesis Framework.
Remove the share links from the content
We need to remove the filter callback Jetpack is using to append or prepend the share links to the post object’s content. By removing this filter, we will no longer see the sharing links at the beginning or end of the post.
Always check if the sharing_display() functions exists. This will let us know if sharing is enabled within the Jetpack plugin. Remove the Jetpack callback function for the WordPress ‘the_content’ filter. Make sure to set the add_action() ‘init’ priority later than 10 to ensure the filter is registered and ready to be removed.
Use a Genesis hook to append our new content
By adding a hook to the Genesis action, ‘genesis_after_entry’ (or ‘genesis_after_content’ for pre-2.0), we can add a custom content box after the content. I reduced the priority down to 5 to ensure it appears immediately after the post content, although this may be different depending on the theme.
Again, check if the sharing_display() functions exists. The sharing_display() function will handle the the options set by the user to determine when and where sharing will appear. If we call this function and receive an empty result, we can jump ship and not display our sharing content.
Within the callback, I added two filters to this callback function; sharedaddy_box_title and sharedaddy_box_content.
The sharedaddy_box_title filter will allow a developer to alter the title… maybe through options or post meta. Last, the sharedaddy_box_content filter will allow a developer to adjust the content all together without adjusting the ‘genesis_after_entry’ callback I created.
Add custom styling
Of course, styling will be needed for presentation and structure of the sharing links.
The styling was made to accommodate my theme. Adjust your css to fit your needs.
Rotating the sharedaddy box title
Since I added filters to the title of the sharedaddy box, a callback can be added to alter the title of the sharedaddy box.
I am rotating the Sharedaddy box title every three posts. This is just a simple example of what can be done with this filter.
Product developer at WPEngine and runner from Hampshire, Illinois. I work with php a lot; Spending most of my time digging into source code to see how it all works. You can find me on Twitter @rfmeier.
View all posts by rfmeier