• Resolved Koesterandersen

    (@koesterandersen)


    According to some closed threads I have a question, that I hope someone could answer.

    Can anyone tell me the difference of these two enqueue codes.

    Nr. 1
    function my_enqueue_parent_theme_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_parent_theme_styles’);

    Nr. 2
    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_theme_style’ );
    function enqueue_parent_theme_style() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }

    They both seem to work, but I wonder why there are two different ones. And then I think that maybe one of them might not work suddenly in a particular situation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Koesterandersen. Seems to be a bit of cross-posting regarding your question. Once you started this post you should have kept that thread active. The reference I gave you in that post to look at this post was just that; a reference. Since you’ve started another post here with the same question you should edit your original post with a link to this post, then mark your original post as Resolved.

    To answer your question, the two code segments are equivalent. The difference is that one declares the add_action before the function, the other declares it after the function. It’s just a matter of coding style; they both do the same thing.

    Thread Starter Koesterandersen

    (@koesterandersen)

    Hi bdbrown

    Thank you for your answers.

    Now when I have messed up in different threads today I might have learned (by accident) how the rules are here in the forum. And with your explanation I can see now, how the forum works. I will try to remember to do it right in the future.

    And thank you for the answer about the difference of the two enqueue functions. Now I have peace in my mind when it comes to this function.

    Have a nice weekend

    And thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘The difference between two almost similar enqueue codes’ is closed to new replies.