I am trying to load my style sheets in my plugin but they are not being called, the javascript files however, are being loaded.

Plugin Name: 
Plugin URI: 
Author URI: 

define("MPF_PATH", ABSPATH . 'wp-content/plugins/' . basename(dirname(__FILE__)).'/' );
define("MPF_URL", trailingslashit(get_option('siteurl')) . 'wp-content/plugins/' . basename(dirname(__FILE__)) . '/' ); 

class mpf_plugin{

function crf_user_registration(){
    add_action('plugins_loaded', array(&$this, "load_my_scripts"));
    add_action('admin_menu', array(&$this,'add_crf_menu_items'));

        add_shortcode('crf_registration', array(&$this, "do_shortcode"));
    } else {
        //do something else here


function load_my_scripts(){
        wp_register_script('crf_script', MPF_URL . 'includes/js/crf_script.js');
        wp_register_style('crf_style', MPF_URL . 'includes/css/crf_style.css');


        wp_localize_script( 'crf_script', 'MyAjax', array( 'MPF_PATH' => MPF_PATH, 'MPF_URL' => MPF_URL,'ajaxurl' => MPF_URL . 'includes/save-layout.php', 'loadPageLayoutURL' => MPF_URL . 'includes/get-layout.php', 'optionsPageURL' => MPF_URL . 'includes/options.php' ));

function do_shortcode(){


function options_page() {
    // HTML code goes here, left out for brevity

function custom_dropdown_page(){
    // HTML code goes here, left out for brevity

function add_crf_menu_items() {
            'My Plugin Form', 

            'MPF Options', 
            'MPF Options', 


new mpf_plugin();

The paths are all correct. Any ideas as to what is going on?

1 Answer 1


I'll guess it's because plugins_loaded is too early to enqueue styles. The wp_enqueue_scripts action is the appropriate action for enqueueing scripts and styles.

  • Thanks Milo. What would you think is the right action to hook into? And if plugins_loaded is too early then why does the javascript file load?
    – Todd
    Commented Jun 27, 2012 at 18:34
  • without looking into source, I'm not sure why the two would behave differently, but as I mention in my answer wp_enqueue_scripts is the action you should hook. see the example with wp_enqueue_style in codex.
    – Milo
    Commented Jun 27, 2012 at 19:50
  • Thanks again Milo. I had read your first response wrong. Strange, but the style sheets still don't load with this hook. I don't get it.
    – Todd
    Commented Jun 27, 2012 at 21:10
  • Did you see this example Todd? codex.wordpress.org/Function_Reference/… - looks like 'admin_init' is the action to use for registering. Commented Jun 27, 2012 at 21:56
  • @MereDevelopment yes, I have seen that and tried that as well but still to no avail. It has to be something else that is going on as I have the scripts loading just fine using plugins_loaded and admin_init in my other plugins. Thanks for chiming in Mere Dev.
    – Todd
    Commented Jun 27, 2012 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.