Genesisのパンくずリストの表示を変更する方法

StudioPressのWordPressテーマ「Genesis」のパンくずリストの表示を変更する方法です。

Genesis Frameworkの標準では、次のようにパンくずリストに内容と関係のない単語がついてしまいます。

Genesis標準のパンくずリストの表示
Genesis標準のパンくずリストの表示

紹介する方法を使うと、単語を変更したり、単語を削除したりできます。

方法①:breadcrumbs.phpを編集する

Genesis Frameworkのconfig/breadcrumbs.phpを編集します。

<?php
/**
 * Genesis Framework.
 *
 * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package StudioPress\Genesis
 * @author  StudioPress
 * @license GPL-2.0-or-later
 * @link    https://my.studiopress.com/themes/genesis/
 */

/**
 * The breadcrumbs configuration array.
 *
 * If child theme contains a `breadcrumbs.php` config, it will be used instead of this config.
 *
 * @since 2.7.0
 */
return [
	'home'                    => __( 'Home', 'genesis' ),
	'sep'                     => ' <span aria-label="breadcrumb separator">/</span> ',
	'list_sep'                => ', ',
	'prefix'                  => genesis_markup(
		[
			'open'    => '<div %s>',
			'context' => 'breadcrumb',
			'echo'    => false,
		]
	),
	'suffix'                  => genesis_markup(
		[
			'close'   => '</div>',
			'context' => 'breadcrumb',
			'echo'    => false,
		]
	),
	'heirarchial_attachments' => true,
	'heirarchial_categories'  => true,
	'labels'                  => [
		'prefix'    => __( 'You are here: ', 'genesis' ),
		'author'    => __( 'Archives for ', 'genesis' ),
		'category'  => __( 'Archives for ', 'genesis' ),
		'tag'       => __( 'Archives for ', 'genesis' ),
		'date'      => __( 'Archives for ', 'genesis' ),
		'search'    => __( 'Search for ', 'genesis' ),
		'tax'       => __( 'Archives for ', 'genesis' ),
		'post_type' => __( 'Archives for ', 'genesis' ),
		'404'       => __( 'Not found: ', 'genesis' ),
	],
];

方法②:functions.phpを編集する

functions.phpに以下のコードを追記します。

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

//* Modify breadcrumb arguments.
add_filter( 'genesis_breadcrumb_args', 'sp_breadcrumb_args' );
function sp_breadcrumb_args( $args ) {
	$args['home'] = 'Home';
	$args['sep'] = ' / ';
	$args['list_sep'] = ', '; // Genesis 1.5 and later
	$args['prefix'] = '<div class="breadcrumb">';
	$args['suffix'] = '</div>';
	$args['heirarchial_attachments'] = true; // Genesis 1.5 and later
	$args['heirarchial_categories'] = true; // Genesis 1.5 and later
	$args['display'] = true;
	$args['labels']['prefix'] = 'You are here: ';
	$args['labels']['author'] = 'Archives for ';
	$args['labels']['category'] = 'Archives for '; // Genesis 1.6 and later
	$args['labels']['tag'] = 'Archives for ';
	$args['labels']['date'] = 'Archives for ';
	$args['labels']['search'] = 'Search for ';
	$args['labels']['tax'] = 'Archives for ';
	$args['labels']['post_type'] = 'Archives for ';
	$args['labels']['404'] = 'Not found: '; // Genesis 1.5 and later
return $args;
}

参考:StudioPressのModify the Breadcrumbs Displayより

よかったらシェアしてね!
  • URLをコピーしました!