WordPress – How to add an attribute to a plugin inline script tag

The script <script type="text/javascript" id='nf-front-end-js-extra'> is added via the wp_localize_script function, and you can’t add attributes using the script_loader_tag filter. This filter can only be used for scripts added via wp_enqueue_script.

In your case, you should use the wp_inline_script_attributes filter.

Try using the following code:

// NAV: Add attributes to inline script nf-front-end-js-extra 
function wpcoder_to_script ($attributes, $javascript) {
    
    if(isset($attributes['id']) && $attributes['id'] === 'nf-front-end-js-extra') {
        $attributes = array_merge(array( 'data-cookieconsent' => 'ignore' ), $attributes);
    } 
    
    return $attributes;
    
}

add_filter('wp_inline_script_attributes', 'wpcoder_to_script', 10, 2);

You can add this code to the functions.php file or use the free WP Coder plugin through the Global PHP page.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino