Leo
Leo

Reputation: 158

Wordpress Plugin wont load css

My add_action() isn't working and i have no clue why.

This is my php

function mapstyle() {
    wp_register_style('mapstyle', plugins_url('assets/css/mapstyle.css' , __FILE__ ));
    wp_enqueue_style('mapstyle');
}

add_action( 'admin_init','mapstyle');

My css is in 'plugin_folder_name/assets/css/mapstyle.css'

Upvotes: 1

Views: 107

Answers (2)

BambiOurLord
BambiOurLord

Reputation: 372

Try changing your code to the following. Also ensure that you do a hard refresh with CTRL + F5 or CTRL + SHIFT + R to clear cache, sometimes changes will not show up unless cache is cleared.

function mapstyle() {
     //last parameters set to true loads css in the footer instead of header
     wp_enqueue_style('mapstyle', plugins_url('assets/css/mapstyle.css' , __FILE__ ), array(), false, true);

}
add_action( 'wp_enqueue_scripts','mapstyle');

Here is link to documentation of wp_enqueue_style.

Edit: My bad, half way through writing answer forgot you wanted to enqueue css and not js :D

Upvotes: 2

Han
Han

Reputation: 21

Depends on where you want to enqueue the styles--admin vs. front-end:

Admin:

add_action('admin_init', 'mapstyle');

Front-end:

add_action('wp_enqueue_scripts', 'mapstyle');

Reference: https://developer.wordpress.org/reference/functions/wp_enqueue_style/

Upvotes: 0

Related Questions