从woocommerce“添加到购物车”按钮中删除rel =“ nofollow”

时间:2018-09-19 09:52:09

标签: woocommerce

WooCommerce正在将rel =“ nofollow”链接添加到我网站上产品上的“添加到购物车”按钮上,我不知道如何删除它。 我尝试遵循答案here,但无法正常工作。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

您可以使用woocommerce_loop_add_to_cart_args通过WooCommerce循环中的“添加到购物车”按钮取消设置rel属性

add_filter( 'woocommerce_loop_add_to_cart_args', 'remove_rel', 10, 2 );
function remove_rel( $args, $product ) {
    unset( $args['attributes']['rel'] );

    return $args;
}

答案 1 :(得分:0)

我使用此代码。但没有找到如何在“ aria-label”产品标题中插入

// Change rel “nofollow” to rel “dofollow” on Shop Page Product button
add_filter( 'woocommerce_loop_add_to_cart_link', 'add_to_cart_dofollow', 10, 2 );
function add_to_cart_dofollow($html, $product){
    if($product->product_type == 'simple') {
        $html = sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" aria-label="Добавить в корзину" data-product_sku="%s" class="%s" %s>%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( isset( $quantity ) ? $quantity : 1 ),
        esc_attr( $product->get_id() ),
        esc_attr( $product->get_sku() ),
        esc_attr( isset( $args['class'] ) ? $args['class'] : 'button product_type_variable add_to_cart_button' ),
        esc_attr( isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : ''),
        esc_html( $product->add_to_cart_text() )
    );
    }else {
    $html = sprintf( '<a href="%s" data-quantity="%s" data-product_id="%s" aria-label="Выбрать" data-product_sku="%s" class="%s" %s>%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( isset( $quantity ) ? $quantity : 1 ),
        esc_attr( $product->get_id() ),
        esc_attr( $product->get_sku() ),
        esc_attr( isset( $args['class'] ) ? $args['class'] : 'button product_type_variable add_to_cart_button' ),
        esc_attr( isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : ''),
        esc_html( $product->add_to_cart_text() )
    );
    }
    return $html;
}
相关问题