【问题标题】:WooCommerce single product shortcodeWooCommerce 单品简码
【发布时间】:2016-01-01 01:48:41
【问题描述】:

我正在使用 WooCommerce 销售单一产品,因此我没有商店基本页面。现在我已经将产品帖子添加到我的主菜单中,但我想实际使用产品短代码在普通页面上显示完整的单个产品 [product_page_ID="99"],以便我可以轻松地添加其他内容。也,并将此页面添加到我的菜单中。但是我仍然会得到内容基本相同的单个产品帖子(可在 .../shop/product 下访问),我该如何避免这种情况?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    创建一个新页面并向其中添加以下短代码[product_page id="123"](将 123 替换为有效的产品 ID)根据需要添加额外内容,然后将该页面添加到您的菜单中。

    但是我仍然会得到内容基本相同的单个产品帖子(可在 .../shop/product 下访问),我该如何避免这种情况?

    在您的另一个线程上,我为您提供了一些关于重定向商店基地的代码,您需要对其进行修改以包括单个产品页面,这是更新版本:

    add_action( 'template_redirect', 'redirect_shop' );
    
    function redirect_Shop() {
    
        // added is_product() conditional to stop users from accessing the single product page
        if( is_shop() || is_product() ) {
    
            //replace the link below to point to your custom product page
            header('HTTP/1.1 301 Moved Permanently');
            header('location:http://www.example.com/page');
            exit;
    
        }
    }
    

    【讨论】:

    • 非常感谢!这太棒了!这也将避免 SEO 的重复内容,对吗?
    • 刚刚更新了我的答案,并将重定向设为 301 Moved Permanently,这也有助于 SEO
    猜你喜欢
    • 2014-09-20
    • 2017-12-29
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 2018-10-17
    • 1970-01-01
    相关资源
    最近更新 更多