skip to Main Content

I have used following shortcodes in the Home page to display set of products :-

[products limit="15"  orderby="menu_order"  columns="5"  category="shirt, shoe"]

However when any product image is clicked on the Home page, the specific link is opened on the same tab. I would like to open that link in a separate tab. How to achieve this?

Thanks!

Note: I am using Oceanwp as my active theme

2

Answers


  1. Chosen as BEST ANSWER

    Since I am using Oceanwp theme, I have to modify in different places than what is suggested by @Diego. But his answer gives me the clue for finding the solution. This is the modification I did to make it work for Oceanwp.

     if ( ! function_exists( 'ocean_woo_img_link_open' ) ) {
            function ocean_woo_img_link_open() {
                    global $product;
                    $woo_img_link = get_the_permalink( $product->get_id() );
                    echo '<a href="' . esc_url( $woo_img_link ) . '" class="woocommerce-LoopProduct-link" target="_blank" >';
            }
    }
    

  2. Funny, i just had the same issue few days ago. Here’s how i’ve solved it:

    if ( ! function_exists( 'woocommerce_template_loop_product_link_open' ) ) {
        /**
         * Insert the opening anchor tag for products in the loop.
         */
        function woocommerce_template_loop_product_link_open() {
            global $product;
            
            $link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );
            
            echo '<a href="' . esc_url($link) . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link" target="_blank">';
        }
    }
    

    Tested and works. You can just paste this into your functions.php or if you’ve made a custom plugin just include this at the very beginning.

    You might need to add "is_home()" or "is_front_page()" to make it hit just the home page and not the whole site

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search