• Resolved Steven

    (@spstieng)


    I’m building a new plugin and I need to register a css file.
    Looking at Lester ‘GaMerZ’ Chan’s work, he is using the function called wp_register_style().

    add_action('wp_head', 'email_js');
    function email_js() {
      wp_register_style('wp-email', plugins_url('wp-email/email-css.css'), false, '2.40', 'all');
    }

    This works great for his plugin, but why doesn’t it work for me?
    Is it because it’s not a wp function?

    Here is my code:

    add_action('init', 'sl_add_scripts');
    
    function sl_add_scripts() {
      wp_register_style('sl_forms', plugins_url('wp-store-locator/style/sl_forms.css'), false, '1.00', 'all');
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • How about using the following code

    <?php
    
        /*
         * This example will work with WordPress 2.7
         */
    
        /*
         * register with hook 'wp_print_styles'
         */
        add_action('wp_print_styles', 'add_my_stylesheet');
    
        /*
         * Enqueue style-file, if it exists.
         */
    
        function add_my_stylesheet() {
            $myStyleFile = WP_PLUGIN_URL . '/style/sl_forms.css';
            if ( file_exists($myStyleFile) ) {
                wp_register_style('myStyleSheets', $myStyleFile);
                wp_enqueue_style( 'myStyleSheets');
            }
        }
    
    ?>

    See https://codex.www.ads-software.com/Function_Reference/wp_enqueue_style for more details.

    Thread Starter Steven

    (@spstieng)

    What does it actually mean to enqueue something?
    If a script is enqueued, it’s kind of waiting in line to be used?

    means it will be outputed to the browser in a right time not now.
    e.g: after http header, before <body> element.

    Thread Starter Steven

    (@spstieng)

    Thanks guys.

    I had done what tomontoast suggested, except for one thing.
    I had forgottenthe wp_enqueue_style.

    Once i Added this, it worked.

    Thanks guys ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_register_style() not working for me’ is closed to new replies.