Last active
October 17, 2017 14:53
-
-
Save mypacecreator/ffee6296eeb15ca30252 to your computer and use it in GitHub Desktop.
WP SitemanagerまたはPrime Strategy Bread Crumbの拡張
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//パンくずのリッチスニペット対応 | |
function rich_bread_crumb($output, $args) { | |
if ($args['type'] == 'list') { | |
$output = preg_replace('|<li\s+(.*?)>|mi','<li ${1} itemscope="itemscope" itemtype="https://data-vocabulary.org/Breadcrumb">',$output); | |
$output = preg_replace('|<li\s+class="(.*?current.*?)".*?>|mi','<li class="${1}">',$output); | |
$output = preg_replace('|<a\s+(.*?)>|mi','<a ${1} itemprop="url"><span itemprop="title">',$output); | |
$output = str_replace('</a>','</span></a>',$output); | |
} | |
return $output; | |
} | |
add_filter('bread_crumb', 'rich_bread_crumb',10,2); | |
//パンくず階層調整 カスタム分類では間にカスタム投稿アーカイブを追加する | |
function custom_bread_crumb( $bread_crumb_arr ) { | |
global $post; | |
if ( is_tax( 'taxonomy-name' ) ) { | |
$bread_crumb_arr[2] = $bread_crumb_arr[1]; | |
$bread_crumb_arr[1] = array( 'title' => '投稿タイプ名', 'link' => home_url('/path') ); | |
} | |
return $bread_crumb_arr; | |
} | |
add_filter( 'bread_crumb_arr', 'custom_bread_crumb' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment