구글 빙 만 rss 본문 허용 워드프레스 스니펫

아래 코드를 사용해 사용자 에이전트명을 확인해 구글과 빙에게만 RSS 콘텐츠 전체가 보이게 할 수 있다.

// feed content only google, bing . hardfilter.com
function feed_content_user($content) {
	$ua = $_SERVER['HTTP_USER_AGENT'];
	if (strpos($ua, 'Google') === false && strpos($ua, 'bing') === false) {
		return '';
	}
	return $content;
}
add_filter('the_content_feed', 'feed_content_user');

유저명을 안정적으로 여러 타입 구글봇에게 허용하기 위해 Google로 했는데, 정확히 타깃하고 싶으면 Googlebot 으로 바꾸면 됨.

이렇게 설정하면 'Settings' → 'Reading' → 'For each post in a feed' → 'Full text' 로 전체 보이게 설정 해 놓고도, 부정적 피더나 스크래퍼들에겐 요약만 보여주고, 설정한 User-Agent 에게만 전체 내용을 보여줄 수 있음.