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
Social Media Icons: update actions to filters. #2741
Conversation
cc @macmanx2 |
I'd lean towards a different tack here, which would be to leave the current hooks, but then, when creating the social icons, create them as an array which we then filter, then implode. This would make it much easier to insert new icons in the middle, change things for a specific icon, etc. Thoughts? |
That would work for me. |
@samhotchkiss and @jeherve please take a look at my change. I decided to go the way Sam suggested and made the code a little more DRY in the process. This enables users to add any HTML into any place - on the ends of the list as well as in between, also change the order of icons. |
67a5c7f
to
17b95fe
Compare
@zinigor overall looks nice -- could you please provide an example usage that we can put on our support docs? My only real concern is there's no back compatibility for people who have set up the before/after icons with the after/before hooks. It won't throw any errors, but still would be an unexpected result of upgrading to 3.8 |
I don't think we'll need to worry too much about folks using the old after/before hooks. It was never published outside of here, and all the old hooks allowed for was changing the icon. Until this change goes through, there is still no way to provide a custom URL, so we really only have to worry about folks who saw the hooks in code or on GitHub and switched the icons on their existing links, which given the relevance of the icons seems unlikely. I'm sure there are some who did that, there are always some, but I predict the user and support impact from such a change will be incredibly small. |
@zinigor thank you! I was about to start writing a patch for this then found this pull request. Good stuff, I like 👍 |
As actions, it could only echo an additional icon before or after the whole widget.
Prior to that we compiled the widget contents using string concatenation, this change implements array compilation as well as changes filters to enable users to change order of icons and add their arbitrary HTML in between or on both ends.
Props to @brendancarr for proposing the original PR.
61c3bf4
to
03be982
Compare
Added changes from #2654 and rebased this PR, should be good to go now. |
This shows all of the icons that link even if they're not being used. |
Additionally fixed links appearing even when there are no usernames.
Here's an example of how you can use the newly added filter to add a new social network link: function jetpackme_linkedin_company_icon( $html_array ) {
return
$html_array +
array(
25 => // This key can be modified to change the order the new item will appear in the list
'<a title="Automattic" '
. 'href="https://www.linkedin.com/company/automattic" '
. 'class="genericon genericon-linkedin" target="_blank">'
. '<span class="screen-reader-text">Automattic Company Profile</span></a>'
);
}
add_filter( 'jetpack_social_media_icons_widget_array', 'jetpackme_linkedin_company_icon' ); |
Looks good, tests well. Thanks for the example filter. |
…lters Social Media Icons: update actions to filters.
Hello, Redirected here from WordPress support forum and posting a query for more eyes and possible help. I want to add a Flipboard 'Follow us' icon (not a sharing button) to Jetpack Social Icon widget in WordPress. The Flipboard icon is not part of Genericons font but, Flipboard itself offers a JS code to generate an icon.
Though I can use this code in a custom HTML widget to display the icon, but I want it to be part of the Jetpack's social icon widget, such that all social icons (Facebook, Instagram, Flipboard, etc.) are bunched together. Edit: I have also enqueued fontawesome (that has the Flipboard icon) with the following code:
With that in place, is there a way I could modify this GitHub code above to add the Flipboard icon? I am not a programmer. Can someone please help resolve this? Thank you Kind regards, |
Hello @backpackingseries ! We have recently deprecated the widget that this PR is about. Now we are using a different Social Icon Widget to which you can add any links that you want. The problem would be adding the icon to your link, because we don't have one for Flipboard. What I see instead is a link that has
If you have control over your site's theme and can add scripts or styles, you can probably add a style that would target this link with a selector like:
That's assuming that your link to Flipboard is going to be last. The black background setting is just an example of how you can target the link and change the way it looks. Hope that helps! |
Hello @zinigor, Thank you for the help and suggesting a possible solution. I just got off performance testing / tuning the site and had to remove few fonts that were slowing it down. I also realized that one of the plugin I use already loads Font awesome (that offers an icon for Flipboard) from the disk. However, I am not so sure whether I could tap into the local copy of the font (instead of enqueing it separately and incurring additional latency to fetch it) and will give it try along with the code above. Though I have control over adding scripts and styles, my programming skills are limited. If it doesn't work, I will just hope for Jetpack (or Genericons) to add the Flipboard and Bloglovin icons to the social widget sometime soon! Thanks very much once again. Kind regards |
As actions, it could only echo an additional icon before or after the whole widget.
Once this is fixed, site owners will be able to use the filters like in this example: