WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a wrapper shortcut function to register and load stylesheets in the header. currently, the function loads this css file src:


I, obviously want it to pass the parameter given. The problem is, the new function definition within the new function definition doesn't seem to be taking the parameter even though my #4th argument for add_action was 1 (parameter passable to function).

What am I doing wrong?? Please help :)

<?php //Registering stylesheets


function load_stylesheet_like_a_boss($filename){
    echo 'parent:'.$filename; //should return 'parent: my-style.css'
        add_action('wp_head', 'stylesheet_registration', 5, 1); 

        function stylesheet_registration($filename){
        echo ' / child:'.$filename.'<br>'; //should return ' / child: my-style.css'
        $name = str_replace('.css','', $filename);

        wp_register_style($name, get_bloginfo('template_directory').'/css/'.$name.'.css');
        wp_enqueue_style($name, 10);
} ?>
share|improve this question
Why are you trying to create a wrapper for a hook callback? IOW, where/how do you intend to call load_stylesheet_like_a_boss(), and why do you need to use the wrapper, instead of simply creating a hook callback to enqueue your stylesheet? – Chip Bennett Feb 14 '12 at 14:00

While your code is a bit messy, I think the one thing that is breaking it is the wp_enqueue_style you've got there. The second parameter "10" just shouldn't be there.

share|improve this answer
thanks man, made no difference. still didn't work. so I got around it another way, thanks :) – Harley Alexander Oct 1 '11 at 8:36
Harley, you should post your answer here and accept it so that others who are in the same situation can learn from it. – Ian Dunn Sep 14 '12 at 0:52

I think you have a few problems:

  1. The code is unnecessarily complex
  2. You're passing the wrong arguments to wp_enqueue_style(). (You appear to be passing a priority, which this function does not accept.)
  3. You're echoing inside of a callback that isn't intended to output anything
  4. Conceptually, the idea of a wrapper for an enqueue action callback just doesn't seem to make sense.

Try something like this, instead:

function load_stylesheet_like_a_boss( $filename ) {

    if ( false == $filename ) {
    } else {

        function enqueue_stylesheet_like_a_boss( $filename ) {
            // Stylesheet handle
            // Returns all but the ".css" from $filename
            $handle = substr( $filename, 0, -4 );
            // Stylesheet path
            $path = get_template_directory_uri() . '/css/' . $filename;
            // Enqueue
            wp_enqueue_style( $handle, $path );
        add_action( 'wp_enqueue_scripts', 'enqueue_stylesheet_like_a_boss' );


Note: the load_stylesheet_like_a_boss() function must be called prior to the wp_head action firing. That means that it probably shouldn't be called in the template at all, but rather in functions.php, and hooked in somewhere - which causes me to wonder why you need such a wrapper at all?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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