JStormThaKid JStormThaKid - 2 months ago 4x
CSS Question

how to apply stylesheet to wp frontend, via plugin i created?

I am trying to write a plugin that when activated, will apply a stylesheet (located in the plugin folder) to the website that it is activated on, but i'm stuck. Below is how far i have gotten. I think i only have the code to load the stylesheet for the plugin itself? But i want to activate my plugin and apply a stylesheet to the frontend site. Any or all help would be appreciated.

p.s. - i know there are other ways to load styles on the front end... like via your themes custom css section... but for what im working on i need this to be loaded through a plugin i am creating.


* Plugin Name: plugin name
* Plugin URI: http://www.pluginurl.com/
* Description: plugin description
* Version: 1.0
* Author: author name
* Author URI: http://www.authorurl.com/

function register_wprs(){
wp_register_style( 'cta_stylesheet', plugins_url( '/css/rs.css', __FILE__ ) );
wp_enqueue_style( 'cta_stylesheet' );

add_action( 'enqueue_scripts', 'register_wprs' );



.classname { color: #000; }


Assuming this is Wordpress (it looks a lot like Wordpress). The action hook that you want is wp_enqueue_scripts, not enqueue_scripts.

Change your last line to

add_action( 'wp_enqueue_scripts', 'register_wprs' );