What's the difference between get_stylesheet_directory_uri() and get_template_directory_uri() when enqueuing scripts in wordpress

前端 未结 1 378
情书的邮戳
情书的邮戳 2020-12-24 06:47

It\'s not a serious question.

I normally use get_stylesheet_directory_uri() when enqueuing scripts in WordPress, which worked fine so far.

I jus

相关标签:
1条回答
  • 2020-12-24 07:04

    Both functions can be used in a parent or a child theme.

    get_template_directory_uri will always refer to the parent theme folder for assets.

    get_stylesheet_directory_uri will refer to the "current" theme folder for assets (which could be the parent or the child, depending on where it is called).

    For example, in a child theme:

    // This will point to style.css in child theme
    wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );
    
    // This will point to style.css in the parent theme
    wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );
    

    Note that if a theme is not a child theme, then it is considered a parent theme.

    0 讨论(0)
提交回复
热议问题