Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress get_template_directory_uri is not working with a child theme

Tags:

wordpress

So I am using mr tailor together with a child theme. The theme folders are named accordingly: mrtailor and mrtailor-child.

But in the theme manager in dashboard they are called: Mr. Tailor and Mr. Tailor Theme. Just mentioned this, because it usually adds the child in the end instead of a theme.

The problem is that I override some of the function and place them into the child theme. The scripts run well, bet the get_template_directory_uri() returns the parent theme's uri.

Here is an example of one of the overriden functions if that is going to help:

<div class="row">
    <div class="large-10 text-center large-centered columns">

        <div class="cart-empty-banner cart-wishlist-empty-banner">
            <img id="cart-empty-img" alt="cart-empty-image"  width="480" height="233"  src="<?php echo get_template_directory_uri() . '/images/empty_cart_black.png'; ?>" data-interchange="[<?php echo get_template_directory_uri() . '/images/empty_cart_black.png'; ?>, (default)], [<?php echo get_template_directory_uri() . '/images/empty_cart_black_retina.png'; ?>, (retina)]">
        </div>

        <p class="cart-empty cart-wishlist-empty"><?php _e( 'Your cart is currently empty.', 'mr_tailor' ) ?></p>

        <?php do_action( 'woocommerce_cart_is_empty' ); ?>

        <p class="return-to-shop"><a class="wc-backward" href="<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>"><?php _e( 'Return To Shop', 'mr_tailor' ) ?></a></p>

    </div><!-- .large-10-->
</div><!-- .row-->

Any help or guidance is much appreciated.

like image 200
Domas Avatar asked Jul 22 '14 08:07

Domas


2 Answers

That is what get_template_directory_uri() do, it retrieve the template directory of a theme, or in other words, the parent theme

For child themes, you should be using get_stylesheet_directory_uri() which retrieves the stylesheet directory path, which is used by child themes

like image 192
Pieter Goosen Avatar answered Oct 20 '22 03:10

Pieter Goosen


You can use get_stylesheet_directory() to include any file in your child theme functions.php file. Here is an example;

include (get_stylesheet_directory() . '/myWidget/newsWidget.php');
where I have `newsWidget.php` file in myWidget folder which is in childtheme directory.

Remember the crucial difference between

get_stylesheet_directory() and get_stylesheet_directory_uri() where the former will redirect you to child Theme directory while latter will redirect you to style.css file of your child theme.

like image 32
Naved Ali Avatar answered Oct 20 '22 03:10

Naved Ali