WordPress.org

Ready to get started?Download WordPress

Forums

Simple Share Buttons Adder
[resolved] CSS should only be included on selected pages (5 posts)

  1. kakgungor
    Member
    Posted 9 months ago #

    I have been using the Simple Share Buttons Adder plugin for a few weeks, but I believe it could be improved to increase the efficiency of WordPress sites that rely on it.

    At the moment, I only check "Posts" as the location for displaying the Simple Share Buttons and the plugin respects my wishes - it doesn't publish buttons on my Homepage, Pages, or Categories/Archives. Unfortunately, it still places a link to the page-styles.css file and inserts inline CSS code on ALL pages, even those which are not checked off in the settings.

    I have tweaked the plugin code myself to adjust for this, but I think it is something that should be incorporated by the author. My adjustment was to encapsulate each of the two CSS-related functions (ssba_page_scripts and get_ssba_style) with the following if statement:

    if (is_page() && $arrSettings['ssba_pages'] == 'Y' || is_single() && $arrSettings['ssba_posts'] == 'Y' || is_category() && $arrSettings['ssba_cats_archs'] == 'Y' || is_archive() && $arrSettings['ssba_cats_archs'] == 'Y' || is_home() && $arrSettings['ssba_homepage'] == 'Y' || $booShortCode == TRUE) { //CSS CODE HERE }

    This is the exact same code that the plugin uses to determine if the share buttons should be included on a given page. The plugin should do a similar check and exclude all CSS from pages where it is not needed.

    I know it is a small change, but every little bit of extra code slows down a site, so it would be nice to keep things as clean as possible.

    If anyone is curious to see a working example what I've described above, please feel free to look at my site - the CSS and buttons should be missing from everything except for the individual post pages.

    By the way, thanks for the great plugin!

    http://wordpress.org/plugins/simple-share-buttons-adder/

  2. yellowhousedesign
    Member
    Posted 3 months ago #

    Great idea kakgungor!

    I noticed that same thing and came across your solution... would love to see this implemented by the plugin author

  3. David Neal
    Member
    Plugin Author

    Posted 3 months ago #

    Thanks for the suggestion!

    Could you please submit a pull request on GitHub, I had a go at implementing this briefly but to no avail! https://github.com/davidsneal/simplesharebuttons

    Thanks

  4. yellowhousedesign
    Member
    Posted 3 months ago #

    I just submitted a pull request on GitHub based on kakgungor's suggestions.

    Thanks!

  5. David Neal
    Member
    Plugin Author

    Posted 3 months ago #

    Thank you!! This change has been accepted and shall be included in version 3.8!

Reply

You must log in to post.

About this Plugin

About this Topic