Site icon Hip-Hop Website Design and Development

wp_add_inline_style in plugin not working

I’m making an attempt to make use of wp_add_inline_style in plugin. I need to add some fashion when shortcode runs.

add_action('wp_enqueue_scripts', 'cod_enqueue_scripts');
add_shortcode('cod', 'cod_process_shortcode');

perform cod_enqueue_scripts() {
    wp_enqueue_style('cod-style', plugins_url('css/fashion.css', __FILE__));
}

perform cod_process_shortcode(){
    $inline_css = "
        .icon-color{
            colour:#ad3;
        }";

    wp_add_inline_style('cod-style', $inline_css);
}

This does not work, It won’t hook to ‘cod-style’.

It really works if I do that: (first enqueue CSS then name wp_add_inline_style instantly afterwards)

perform cod_process_shortcode(){
    wp_enqueue_style('cod-custom', plugins_url('css/clean.css', __FILE__));
    $inline_css = "
        .icon-color{
            colour:#ad3;
        }";

    wp_add_inline_style('cod-custom', $inline_css);
}

Within the above instance, I used an empty CSS file (clean.css) for testing.

I although perhaps my unique css file shouldn’t be loaded but, however even when I enqueue empty css in cod_enqueue_scripts, it’s going to wont do it, like this:

perform cod_enqueue_scripts() {
    wp_enqueue_style('cod-style', plugins_url('css/clean.css', __FILE__));
}

perform cod_process_shortcode(){
    $inline_css = "
        .icon-color{
            colour:#ad3;
        }";

    wp_add_inline_style('cod-style', $inline_css);
}

I do not know what inline CSS I would like till shortcode runs, and appears odd that the wp_add_inline_style won’t hook to unique wp_enqueue_style.