skip to Main Content

I want to create a WordPress Plugin where I want to add some css, and upon activation, those css will be in effect and be viewing in the website. Upon deactivation, the css will also be out of effect.

Any how I can do that? Or any documentation I can take help from?

2

Answers


  1. You can follow Plugin Handbook for creating a plugin https://developer.wordpress.org/plugins/.

    create a CSS file in plugin directory then upon plugin activation hook you can enqueue the CSS file using action ‘wp_enqueue_style’.

    Login or Signup to reply.
  2. You can add this to your main file to load your css file:

    function add_my_css() {
        $plugin_url = plugin_dir_url( __FILE__ );
        wp_enqueue_style( 'style',  $plugin_url . "/css/plugin-style.css");
    }
    
    add_action( 'wp_enqueue_scripts', 'add_my_css' );
    

    Then create your plugin-style.css file and write your css.

    Hope this helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search