skip to Main Content

Here is a solution to remove the meta “noindex” which causes an issue for the myaccount page to be indexed in google, because some people want it to appear for their clients to easy find the login page.

The function match the my-account page and then remove the meta

function remove_wc_page_noindex(){

    $url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if ( false !== strpos( $url, 'my-account' ) ) {
    remove_action( 'wp_head', 'wc_page_noindex' );
}
}

add_action( 'init', 'remove_wc_page_noindex' );

My question: is there is a way to directly locate the my account page instead of matching part of the url?

2

Answers


  1. You can get more details about the conditional tags here.

    /**
     * Disable/Enable search engines indexing myaccount pages.
     *
     */
    
    function is_wc_page_noindex() {
    
        if ( is_page( wc_get_page_id( 'myaccount' ) ) ) {
            remove_action( 'wp_head', 'wc_page_noindex' );
        }
    }
    
    add_action( 'template_redirect', 'is_wc_page_noindex' );
    
    Login or Signup to reply.
  2. Since WP 5.7, Woocommerce uses the wp_robots filter. If remove_action( 'wp_head', 'wc_page_noindex' ) did not work for you, then you can try the following:

    // Remove WooCommerce noindex meta in cart, checkout and myaccount pages
    
    add_action( 'template_redirect', 'srj_woo_remove_noindex' );
    
    function srj_woo_remove_noindex() {
      if ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) || is_page( wc_get_page_id( 'myaccount' ) ) ) {
        remove_filter( 'wp_robots', 'wc_page_no_robots', 10 );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search