-
-
Save sou-lab/8a7fc6baf0e3af6a92659c374ecc0751 to your computer and use it in GitHub Desktop.
WP SitemanagerまたはPrime Strategy Bread Crumbの拡張(type string対応版)
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="http://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); | |
} elseif ($args['type'] == 'string') { | |
$output = preg_replace('|<a\s+(.*?)>|mi','<span itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb"><a ${1} itemprop="url"><span itemprop=”title”>',$output); | |
$output = preg_replace('|<strong\s+class="(.*?current.*?)".*?>|mi','<span class="${1}">',$output); //現在地のstrongをspanに(お好みで) | |
$output = str_replace('</strong>','</span>',$output); | |
$output = str_replace('</a>','</span></a></span>',$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