• Resolved longjorn

    (@longjorn)


    4.2.2 is loading related.css in footer and widget.css in header.
    I am using a custom template with my own styling which gets changed now by the related.css loading last..??
    Using custom php under ‘Display options’ I want to be able to display related post in my own style.
    Can anyone tell me how to disable css loading or how to override styles which are loading at the end and are set to !important?

    Switching back to 4.2.1 now ..

    https://wordpress.org/plugins/yet-another-related-posts-plugin/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Took me a minute, but this finally worked for me:

    //add this to your functions.php
    
    add_action('wp_print_styles','lm_dequeue_header_styles');
    function lm_dequeue_header_styles()
    {
      wp_dequeue_style('yarppWidgetCss');
    }
    
    add_action('get_footer','lm_dequeue_footer_styles');
    function lm_dequeue_footer_styles()
    {
      wp_dequeue_style('yarppRelatedCss');
    }
    Thread Starter longjorn

    (@longjorn)

    great! thank you, it’s working

    Thanks! Exactly what I needed.

    Plugin Author YARPP

    (@jeffparker)

    By the way, we’re looking for YARPP beta testers. Please email us at contact@yarpp.com if you’re interested in providing invaluable feedback. Thanks!

    I’m having sort of the same problem as OP.

    4.2.2 is loading both widget.css and related.css in the header. I want to dequeue (remove) both.

    widget.css is easily removed thru wp_dequeue_style:

    function my_theme_remove_assets_header() {
      wp_dequeue_style('yarppWidgetCss');
    }
    add_action( 'wp_print_styles', 'my_theme_remove_assets_header' );

    However, if I try the same approach for related.css, that stylesheet instead gets loaded in the footer, with the scripts. If I then try to dequeue it with get_footer, eg.

    function my_theme_remove_assets_footer() {
      wp_dequeue_style('yarppRelatedCss');
    }
    add_action( 'get_footer', 'my_theme_remove_assets_footer' );

    – it’s just loaded in the header instead.

    I’ve tried dequeue’ing this stylesheet in both header & footer; tried using wp_enqueue_scripts; tried both dequeue’ing and deregistering, experimented with varying values for load priority (third parameter to add_action), but I just can’t seem to get related.css removed completely.

    Any help/info greatly appreciated — and thanks for an awesome plugin!

    WP 3.9.1, YARPP (Basic) 4.2.2, Apache 2.2.26, PHP 5.4.24

    Thread Starter longjorn

    (@longjorn)

    the solution Abro gave above is working fine on all sites I use.
    just copied and pasted to functions.php and there is no css loading anymore

    @longjorn – I tried that at first, copy/pasted verbatim.

    That resulted in related.css being loaded in the header again (<head>, to be absolutely clear), which in turn sent me down the rabbit hole of trying every possible option for removing the stylesheet :S (With wp_dequeue_style('yarppRelatedCss'); included in both functions being the first course of action).

    Alas, no dice. Thanks though!

    Also, @jeffparker – please let me know if you need me to start another thread for this issue.

    Plugin Author YARPP

    (@jeffparker)

    Casper, I’m not sure what to tell you. The code works for me and for many other users. Perhaps you’re placing it in an odd location in the functions.php file?

    Thanks for replying, Jeff.

    That’s unfortunately also the hunch I was having.
    I’ll go through everything, to see if there’s some other code inflicting this pain on me 🙂

    FWIW, it’s a new theme I’m coding, so there’s only a couple plugins installed at the moment, and no weird/crazy customizations going on. I’m using the Roots framework, if that’s relevant. Here’s the code in my functions.php:

    <?php
    /**
     * Custom functions
     */
    
    function my_theme_deregister_plugin_assets_header() {
      wp_dequeue_style('yarppWidgetCss');
    }
    add_action( 'wp_print_styles', 'my_theme_deregister_plugin_assets_header' );
    
    function my_theme_deregister_plugin_assets_footer() {
      wp_dequeue_style('yarppRelatedCss');
    }
    add_action( 'get_footer', 'my_theme_deregister_plugin_assets_footer' );

    I’ll post back with whatever I find out.

    Thanks again!

    I’m using Roots too. Try using the wp_footer action instead. For example:

    function my_theme_deregister_plugin_assets_footer() {
      wp_dequeue_style('yarppRelatedCss');
    }
    add_action( 'wp_footer', 'my_theme_deregister_plugin_assets_footer' );

    Thanks @ablears

    Using the wp_footer action didn’t help, however – I then tried deregistering the file in the function that runs before, using wp_print_styles. That finally achieved my goal of removing the two plugin stylesheets. So thanks for putting me on the right track 🙂

    For reference, here’s the code I have in my functions.php now:

    function my_theme_deregister_plugin_assets_header() {
      wp_dequeue_style('yarppWidgetCss');
      wp_deregister_style('yarppRelatedCss');
    }
    add_action( 'wp_print_styles', 'my_theme_deregister_plugin_assets_header' );
    
    function my_theme_deregister_plugin_assets_footer() {
      wp_dequeue_style('yarppRelatedCss');
    }
    add_action( 'wp_footer', 'my_theme_deregister_plugin_assets_footer' );

    I just had the same problem as @casper, I couldn’t remove the related.css from the footer even with the wp_print_styles hook.

    Adding the action to the wp_footer solved it finally.

    Thanks guys 🙂

    Same problem as @casper using quark template.
    Only adding the action with wp_footer is preventing related.css to be loaded in the header… weird.

    @casper’s solution works for me on WP 4.0, the original one did not.

    Yarpp, make it an option when using custom templates!!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘prevent loading related.css and widget.css’ is closed to new replies.