admin管理员组

文章数量:1410706

I'm using the plugin 'Ninja From' and I'm trying to stop it from loading a CSS file in the header.

The CSS file:

<link rel='stylesheet' id='nf-display-css'  href='.css?ver=4.7.1' type='text/css' media='all' />

My code:

function remove_css_ninja_form(){
    wp_dequeue_style('nf-display-css');
    wp_deregister_style('nf-display-css');
}

add_action( 'wp_enqueue_scripts', 'remove_css_ninja_form', 99999 );
add_action( 'wp_print_styles', 'remove_css_ninja_form', 99999 );
add_action( 'wp_head', 'remove_css_ninja_form', 9999 );

It is not working.

I'm using the plugin 'Ninja From' and I'm trying to stop it from loading a CSS file in the header.

The CSS file:

<link rel='stylesheet' id='nf-display-css'  href='http://example/wp-content/plugins/ninja-forms/assets/css/display-structure.css?ver=4.7.1' type='text/css' media='all' />

My code:

function remove_css_ninja_form(){
    wp_dequeue_style('nf-display-css');
    wp_deregister_style('nf-display-css');
}

add_action( 'wp_enqueue_scripts', 'remove_css_ninja_form', 99999 );
add_action( 'wp_print_styles', 'remove_css_ninja_form', 99999 );
add_action( 'wp_head', 'remove_css_ninja_form', 9999 );

It is not working.

Share Improve this question asked Jan 15, 2017 at 20:33 RexRex 1 1
  • sorry for the typo. – Rex Commented Jan 15, 2017 at 20:43
Add a comment  | 

3 Answers 3

Reset to default 0

Extract the ninja form plugin's files to a folder, and use a text editor such as Notepad++ to search within the files of the plugin and find either one of these phrases:

`wp_enqueue_style` OR `css_ninja_form`

You will end up with at least 1 result, which will be similar to :

add_action( 'wp_enqueue_scripts', 'css_ninja_form', xyz );

Which xyz is the priority the author of the plugin used to enqueue it. Now, you can directly remove the line from the result page (not recommended) or you can use the xyz priority to dequeue the script in your function.php.

You need to dequeue the style in nf_display_enqueue_scripts like this :

add_action('nf_display_enqueue_scripts', function () {
  wp_dequeue_style('nf-font-awesome');
  wp_dequeue_style('nf-display');
});

In WordPress priority $arg, Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

So in your functions file, I'd suggest you use:

add_action( 'wp_head', 'remove_css_ninja_form', 0 );

本文标签: wp enqueue styleStooping a css file from loading in the header