Support » Plugin: AMP » Exclude particular css from AMP in paired mode

  • Resolved luckyankit

    (@luckyankit)


    Hi, this code for excluding css below doesn’t work for the paired mode. Although I didn’t check other modes but surely didn’t worked for excluding the css.

    add_action( 'wp_enqueue_scripts', function() {
        if ( function_exists( 'is_amp_endpoint' && is_amp_endpoint() ) ) {
            wp_dequeue_style( 'css-style-id' );
        }
    }, 1000 );

    Also please share the new code with the support of excluding multiple css. TIA

    • This topic was modified 2 months, 2 weeks ago by  luckyankit.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Search through your codebase for the theme/plugin that enqueues css-style-id in the first place. Which action and which priority is it being done at?

    Here are the codes I found:

    wp_enqueue_style('skin-'.$site_skin, get_template_directory_uri( __FILE__ )."/css/skins/".$site_skin.".css");

    Also, there are other urls by the plugins:

    // front style
            wp_register_style(
                'wpel-style'
                , plugins_url( '/public/css/wpel.css', WPEL_Plugin::get_plugin_file() )
                , array()
                , $plugin_version
            );

    another one

    wp_enqueue_style( 'crp-public', CustomRelatedPosts::get()->coreUrl . '/dist/public.css', array(), CRP_VERSION, 'all' );

    So I guess there is no defined priority?

    Plugin Author Weston Ruter

    (@westonruter)

    So are the wp_enqueue_style() calls being made directly inside of a template or shortcode/widget/block render callback?

    it’s in the template. I found the code inside the theme functions.php file. This is in reference to the first code.

    • This reply was modified 2 months, 2 weeks ago by  luckyankit.
    Plugin Author Weston Ruter

    (@westonruter)

    Calling wp_dequeue_style() should still work when wp_enqueue_style() was previously called directly in the template and not inside of a wp_enqueue_scripts action.

    Actually, I can see there is a bug on the code above. There is a misplaced parenthesis:

    🚫

    add_action( 'wp_enqueue_scripts', function() {
        if ( function_exists( 'is_amp_endpoint' && is_amp_endpoint() ) ) {
            wp_dequeue_style( 'css-style-id' );
        }
    }, 1000 );

    add_action( 'wp_enqueue_scripts', function() {
        if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
            wp_dequeue_style( 'css-style-id' );
        }
    }, 1000 );

    Thanks a lot, That worked. Can you please tell me how to add multiple CSS ID’s in it?

    Plugin Author Weston Ruter

    (@westonruter)

    Just duplicate the wp_dequeue_style() call.

    add_action( 'wp_enqueue_scripts', function() {
        if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
            wp_dequeue_style( 'css-style-id1' );
            wp_dequeue_style( 'css-style-id2' );
            wp_dequeue_style( 'css-style-id3' );
            // ...
        }
    }, 1000 );

    Thanks a lot.

    Above code doesn’t work every time, no idea why. Plus it’s not working for excluding CSS by plugins. As I searched online, I think we need to include de-registering to make it work.

    • This reply was modified 2 months, 2 weeks ago by  luckyankit.
Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.