• Resolved sarah semark

    (@tinkerbelly)


    Since it’s quite painful to overwrite sharing styles (see #1500 and #1922) and it’s loading a bunch of CSS I don’t need or want, I’d like to dequeue sharing.css from my theme.

    I’m struggling to figure out how. I know there’s a checkbox one can check to disable both the css _and_ the JS, but I’d like to keep the JS. Is there any way to remove _just_ the CSS file?

    For reference, here’s what I’ve tried, in various different incarnations and levels of desperation:

    `
    add_filter( ‘jetpack_sharing_counts’, ‘__return_false’, 99 );
    add_filter( ‘jetpack_implode_frontend_css’, ‘__return_false’, 99 );

    function smittenkitchen_deregister_styles() {
    wp_deregister_style( ‘sharing’ );
    wp_dequeue_style( ‘sharing’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘smittenkitchen_deregister_styles’, -1 );
    add_action( ‘wp_print_styles’, ‘smittenkitchen_deregister_styles’, -1 );
    `

    I’m sure there’s a simple way to get rid of it, but I’ve been banging my head against the wall trying to suss out what the magic combination is.

    Thanks in advance for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support supernovia

    (@supernovia)

    Hi there @tinkerbelly! I’m comparing what you’ve got to the most current how-to I can find:
    https://css-tricks.com/snippets/wordpress/removing-jetpack-css/

    The only difference I’m seeing is add_action( ‘wp_enqueue_scripts’, ‘smittenkitchen_deregister_styles’, -1 ); — if you take that out does it work?

    Thread Starter sarah semark

    (@tinkerbelly)

    add_filter( ‘jetpack_sharing_counts’, ‘__return_false’, 99 );
    add_filter( ‘jetpack_implode_frontend_css’, ‘__return_false’, 99 );

    works to get rid of the majority of Jetpack styles, but sharing.css is still loaded. The smittenkitchen_deregister_styles here is attempting to dequeue the sharing stylesheet, but it has no effect, I suspect because the stylesheet is loaded with quite aggressive priority in order to overwrite theme styles (which is part of what makes it so difficult to work with).

    I’ve looked all over for documentation but I can’t seem to find anything that works. I did another search this morning and _finally_ came across the solution:

    
    function smittenkitchen_remove_sharedaddy_styles() {
        remove_action( 'wp_head', 'sharing_add_header', 1 );
    }
    add_action( 'template_redirect', 'smittenkitchen_remove_sharedaddy_styles' );
    

    Thanks for your help! I can imagine this snippet would be helpful to others in the future, so it would be great to add it to the documentation. (My future self would almost invariably appreciate it.)

    Cheers!

    • This reply was modified 6 years, 1 month ago by sarah semark.
    Plugin Support supernovia

    (@supernovia)

    Thank you very much!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sharing: How to dequeue sharing.css’ is closed to new replies.