Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to preventing multiple icons on one page #23

Open
jakeparis opened this issue Oct 25, 2022 · 2 comments
Open

Add setting to preventing multiple icons on one page #23

jakeparis opened this issue Oct 25, 2022 · 2 comments

Comments

@jakeparis
Copy link

Our template does some things directly using the the_content filter multiple times, which is causing the social buttons to show up in each of those cases. Perhaps we can add a setting that prevents the buttons from showing more than once?

If you'd like, I can put in a PR with that change.

@JiveDig
Copy link

JiveDig commented Oct 25, 2022

Hey @jakeparis, this sounds like something needs to use the is_main_query() conditional in your template. SSS only renders the template if it is the main query, see the guard clause here https://github.com/robincornett/scriptless-social-sharing/blob/master/includes/output/class-scriptlesssocialsharing-output.php#L31. If your template is using the_content multiple times within the main query, that may be the issue.

@jakeparis
Copy link
Author

I don't think that really gets at the issue here. We only have one call to WP_Queryon the page; only one query. But in our footer, we are getting data (contact information) from options and running it through the_content in order to "texturize" the output, etc. So at that point in the template, WP thinks is_main_query() == true because we've never run any other WP_Query. However, we obviously don't want to keep displaying the social icons for every chunk every text we run through the filter.

Another idea to solve for this (beyond the "setting that prevents the buttons from showing more than once" suggested in the initial post) might be to add support for entering a custom hook name in the text field. Then we could hook into something more appropriate than the_content (at least for our situation).

I realize we could fire the buttons programmatically in our code, but I'm trying for a solution that doesn't marry our code to any specific plugin. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants