WordPress.org

Forums

Yet Another Related Posts Plugin (YARPP)
[resolved] prevent loading related.css and widget.css (16 posts)

  1. longjorn
    Member
    Posted 1 year ago #

    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/

  2. Abro
    Member
    Posted 1 year ago #

    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');
    }
  3. longjorn
    Member
    Posted 1 year ago #

    great! thank you, it's working

  4. Sho-Down
    Member
    Posted 1 year ago #

    Thanks! Exactly what I needed.

  5. jeffparker
    Member
    Plugin Author

    Posted 1 year ago #

    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!

  6. Casper
    Member
    Posted 1 year ago #

    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

  7. longjorn
    Member
    Posted 1 year ago #

    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

  8. Casper
    Member
    Posted 1 year ago #

    @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!

  9. Casper
    Member
    Posted 1 year ago #

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

  10. jeffparker
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  11. Casper
    Member
    Posted 1 year ago #

    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!

  12. ablears
    Member
    Posted 1 year ago #

    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' );
  13. Casper
    Member
    Posted 1 year ago #

    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' );
  14. Zsolti
    Member
    Posted 1 year ago #

    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 :)

  15. bluantinoo
    Member
    Posted 11 months ago #

    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.

  16. aplusdesign
    Member
    Posted 11 months ago #

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

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Yet Another Related Posts Plugin (YARPP)
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.