Các đoạn code hữu ích loại bỏ Rich Snippets, Meta Data… trong Rank Math

Các code này rất cần thiết trong tùy chỉnh SEO, hoặc them đã có sẵn loại Rich Snippets này rồi thì các bạn nên xóa đi để tránh bị trùng lặp.

Các đoạn code hữu ích loại bỏ Rich Snippets, Meta Data... trong  Rank Math

Rich Snippets

Rank math plugin tốt nhưng để tùy chỉnh structured data cũng không quá dễ dàng đâu, nếu bạn cần xóa bất kì Rich Snippets nào thì hãy sử dụng đoạn code sau:

Bộ lọc để loại bỏ WebSite Snippet trên trang chủ:


add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    if ( isset( $data['WebSite'] ) && isset( $data['WebSite']['potentialAction'] ) ) {
        unset( $data['WebSite'] );
    }
    return $data;
}, 11, 2);

Nếu chỉ xóa mình thuộc tính SearchAction trong WebSite Snippet trang chủ thì dùng 1 trong 2 code sau:

add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    if ( isset( $data['WebSite'] ) && isset( $data['WebSite']['potentialAction'] ) ) {
        unset( $data['WebSite']['potentialAction'] );
    }
    return $data;
}, 11, 2);
//Disable the SearchAction json_ld data
add_filter('rank_math/json_ld/disable_search', '__return_true');

Bộ lọc để loại bỏ Blog Snippet trên trang chủ:

add_filter( 'rank_math/json_ld', function( $data, $json ) {
	if ( is_home() && isset( $data['Blog'] ) ) { 
		unset( $data['Blog'] );
	}
	return $data;
}, 11, 2);

Bộ lọc xóa bỏ Breadcrumb Snippet JSON-LD

add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) {
	return $entity;
});

Khác

Bộ lọc để loại bỏ các tham số truy vấn ?replytocom khỏi URL

/**
 * Filter: 'rank_math_remove_reply_to_com' - Allow or disable the Rank Math feature that removes `?replytocom` 
 * query parameters from URLs.
 * @param bool $return True to remove, false not to remove.
 */
add_filter( 'rank_math/frontend/remove_reply_to_com', '__return_false');

Xóa rank-math-link trong bài viết frontend.

/**
 * Filter to remove `rank-math-link` class from the frontend content links
 */
add_filter( 'rank_math/link/remove_class', '__return_true' );

Lọc để thêm các plugin Table of Content List giúp dễ chấm điểm seo hơn.

/**
 * Filter to add plugins to the TOC list.
 *
 * @param array TOC plugins.
 */
add_filter( 'rank_math/researches/toc_plugins', function( $toc_plugins ) {
       $toc_plugins['plugin-directory/plugin-filename.php'] = 'Plugin Name';
    return $toc_plugins;
});

Filter to remove rel=”noopener” from external links.

/**
 * Filter code to remove noopener rel from external links.
 */
add_filter( 'rank_math/noopener', '__return_false');

Tùy chỉnh thêm mạng xã hội vào dữ liệu có cấu trúc Organization

/**
* Collect data to output in JSON-LD.
*
* @param array $unsigned An array of data to output in json-ld.
* @param JsonLD $unsigned JsonLD instance.
*/
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
	$currentSameAs = $data['Organization']['sameAs'];
        $currentSameAs[] = "https://linkeding url....";
        $currentSameAs[] = "https://instagram url....";
        // And so on...

        $data['Organization']['sameAs'] = $currentSameAs;
	return $data;
}, 10, 2);

Các bạn có thể tham khảo thêm các mã dành cho dev tại đây.

4.7/5 - (3 bình chọn)
Developed by blognhatha.com DMCA.com Protection Status