Skip to content

Don't add sharing buttons to sidebars, only to the main content block#2869

Closed
joeytwiddle wants to merge 1 commit into
Automattic:masterfrom
joeytwiddle:master
Closed

Don't add sharing buttons to sidebars, only to the main content block#2869
joeytwiddle wants to merge 1 commit into
Automattic:masterfrom
joeytwiddle:master

Conversation

@joeytwiddle

Copy link
Copy Markdown

We had a problem that we used register_sidebar() twice to create a couple more blocks on our page.

Each block was firing the the_content filter. And so we ended up with three sets of sharing buttons on our page, instead of just the one we wanted in the main content area. (The theme we are using is layerswp.)

This patch fixes the issue, by checking whether we are in the main content block or not. I saw the technique recommended in the links below.

In fact ! in_the_loop() was enough in our case, but the ! is_main_query() check is recommended here: http://wordpress.stackexchange.com/questions/67716/how-to-determine-if-a-filter-is-called-in-a-sidebar-widget-context

Some more tips here: https://pippinsplugins.com/playing-nice-with-the-content-filter/

I have already submitted a similar patch to a different plugin: https://wordpress.org/support/topic/avoid-adding-to-secondary-blocks-created-on-the-page-eg-with-register_sidebar

Cheers!

@jeherve jeherve added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons labels Oct 22, 2015
@jeherve

jeherve commented Oct 22, 2015

Copy link
Copy Markdown
Member

That patch might cause issues for those who do want the sharing buttons to appear in the sidebar, though.

In the past, we've used the sharing_show filter to remove sharing buttons in specific areas of a theme, like in Twenty Fourteen's Ephemera widget for example:
https://github.com/Automattic/jetpack/blob/3.7.2/modules/theme-tools/compat/twentyfourteen.php#L42-L57

To avoid breaking things for everyone using sharing buttons in their sidebar, it might be better for you to do something similar in your own theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants