Canonical Tag to WooCommerce Categories Paginated Content: Canonical към главна категория при станициране

No Comments

Canonical Tag за да класирате основната категория, а не страницирането. Ако използвате плъгина Rank Math SEO, със стъпките по-долу, създавате правилен Canonical Tag, който при станициране сочи към главната категория в WooCommerceWordPress базиран онлайн магазин.

Резултат:
<link rel=“canonical“ href=“https://fantasticweb.bg/c/kursove/“ />
<link rel=“prev“ href=“https://fantasticweb.bg/c/kursove/“ />
<link rel=“next“ href=“https://fantasticweb.bg/c/kursove/page/3″ />

Следвайте стъпките и направете лесно вашата категория с правилно сочещ Canonical Tag:

  1. Копирате кода и го добавяте във function.php файла на дъщерната тема (Child Theme).

add_filter( 'woocommerce_page_title', function( $title ) {
    return $title;
});

add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    if ( is_product_category() && is_paged() ) {
        // Вземаме текущата продуктова категория
        $category = get_queried_object();
        if ( $category && isset( $category->term_id ) ) {
            // Задаваме каноничния URL към главната категория
            $canonical = trailingslashit( get_term_link( $category->term_id, 'product_cat' ) );
        }
    }
    return $canonical;
});

add_filter( 'rank_math/frontend/pagination_prev', function( $prev ) {
    if ( is_product_category() && is_paged() ) {
        // Задаваме правилния prev линк със структура ?page=n
        $current_page = max( 1, get_query_var( 'paged' ) );
        $prev_page = $current_page - 1;

        if ( $prev_page > 1 ) {
            $category = get_queried_object();
            $prev = trailingslashit( get_term_link( $category->term_id, 'product_cat' ) ) . '?page=' . $prev_page;
        } else {
            $category = get_queried_object();
            $prev = trailingslashit( get_term_link( $category->term_id, 'product_cat' ) );
        }
    }
    return $prev;
});

add_filter( 'rank_math/frontend/pagination_next', function( $next ) {
    if ( is_product_category() && is_paged() ) {
        // Задаваме правилния next линк със структура ?page=n
        $current_page = max( 1, get_query_var( 'paged' ) );
        $next_page = $current_page + 1;

        $category = get_queried_object();
        $next = trailingslashit( get_term_link( $category->term_id, 'product_cat' ) ) . '?page=' . $next_page;
    }
    return $next;
});

При нужда от услуги за персонализиране на уеб сайтове на WordPress или онлайн магазини на WooCommerce, моля, свържете се с нас.

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

There is no form with title: "SEOWP: MailChimp Subscribe Form – Vertical". Select a new form title if you rename it.

More from our blog

See all posts

Leave a Comment