1

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?

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Maged Mohamed
  • 511
  • 5
  • 27

2 Answers2

2

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' );
mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • unfortunately, this doesn't work only the noindex is removed the way we wrote above to select part of url .. can you test it on your end ? – Maged Mohamed May 03 '20 at 12:20
1

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 );
  }
}
Suraj Lulla
  • 489
  • 5
  • 12