最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Loading different header and footer in woocommerce templates (AMP)

programmeradmin2浏览0评论

I would like to use different header and footer in my woocommerce AMP templates instead of default one. I already achieved this but I can’t manage to do it for WooCommerce templates. So let me explain what is happening.

Website is using Storefront theme, and the current structure looks like this: – for the desktop version:

/mytheme/woocommerce/

– for the amp version:

/mytheme/amp/woocommerce/

– In order for the amp woocommerce templates to load, I use this code:

 function woo_amp_directory ($path){
    if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
       $my_path = get_stylesheet_directory() . '/amp/woocommerce/';
       return file_exists( $my_path ) ? 'amp/woocommerce/' : $path;
    }
    return $path;
 }
 add_filter ('woocommerce_template_path', 'woo_amp_directory');

Now I have my custom header & footer in the /mytheme/amp/ directory and I load it using

get_template_part('amp/header', 'amp');
get_template_part('amp/footer', 'amp');

However the WooCommerce templates are using the get_header() & get_footer() function which loads the header from /mytheme/ directory. I would like to override this behaviour so the templates that are in /mytheme/amp/woocommerce/ use my header and footer that are in the /mytheme/amp/.

Basically i would love to be able to use this:

get_template_part('amp/header', 'amp');
get_template_part('amp/footer', 'amp');

instead of default ones.

It doesn’t specifically need to use the get_template_part() function, i just want these templates /mytheme/amp/woocommerce/ to use /mytheme/amp/header.php & /mytheme/amp/footer.php.

I already tried putting header.php and footer.php in /mytheme/amp/woocommerce/auth/ but that didn't work.

发布评论

评论列表(0)

  1. 暂无评论