Search code examples
phpwordpresswoocommercehook-woocommercewoocommerce-subscriptions

Remove WooCommerce noindex meta in myaccount page


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?


Solution

  • 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' );