今日の人気記事

  1. 1ページに表示する最大投稿数を変更 - posts_per_page

WPプラグイン「All in One SEO Pack」とテーマ「Twenty Twelve」の競合対処法

当ページのリンクには広告が含まれています。

スポンサーリンク

WPプラグイン「All in One SEO Pack」とテーマ「Twenty Twelve」の競合(confict)の対処方法を紹介します。

競合(conflict)の原因

WordPressのSEO対策プラグイン「All in One SEO Pack」(タイトル変更設定を使用している場合)と標準テーマ「Twenty Twelve」を一緒に使うとタイトルタグがおかしくなってしまいます。

WPプラグイン「All in One SEO PACK」を利用していない場合は、
「投稿タイトル | ブログ名」 というタイトルになるのですが、WPプラグイン「All in One SEO PACK」を利用すると、
「投稿タイトルブログ名 | ブログ名」 といった、ブログ名押せ押せのタイトルになってしまいます。

これは、テーマ「Twenty Twelve」のfunction.phpに、タイトルの末尾にブログ名を付加する関数が記載されているからです。

function.php

function twentytwelve_wp_title( $title, $sep ) {
	global $paged, $page;

	if ( is_feed() )
		return $title;

	// Add the site name.
	$title .= get_bloginfo( 'name' );

	// Add the site description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title = "$title $sep $site_description";

	// Add a page number if necessary.
	if ( $paged >= 2 || $page >= 2 )
		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );

	return $title;
}
add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );

そのため、ブログ名押せ押せのタイトルになってしまいます。

競合(conflict)の対処方法

function.phpファイル内の関数twentytwelve_wp_title()を削除すればいいのですが、テーマが更新された際に再び同じ操作(削除操作)が必要になります。

そこで、関数twentytwelve_wp_title()によるタイトルフィルターを無効(削除)する方法がいいでしょう。header.phpを以下のように変更すればOKです。

header.php 変更前

<title><?php wp_title( '|', true, 'right' ); ?></title>

header.php 変更後

<?php remove_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); ?>
<title><?php wp_title( '|', true, 'right' ); ?></title>

これでOKです。以上、『WPプラグイン「All in One SEO Pack」とテーマ「Twenty Twelve」の競合対処法』でしたー。

関連記事(一部広告含む)