Written by Anonymous
define('SINGLE_BREADCRUMBS_DEPTH', 'single_breadcrumbs_depth');
if (!function_exists('add_breadcrumbs_setting')):
function add_breadcrumbs_setting() {
?>
<script>
jQuery(function($) {
// 既存の「記事タイトル」設定行を取得(ID指定を修正)
const targetRow = $('#single_breadcrumbs_include_post_1').closest('tr');
// 対象行が存在する場合のみ処理を実行
if (targetRow.length) {
// 取得した行の直前に独自設定項目を挿入
targetRow.before(`
<tr>
<th scope="row">
<label>パンくずの階層</label>
</th>
<td>
<?php
// チェックボックスを生成:最も深いタームを優先するかどうか
generate_checkbox_tag(
SINGLE_BREADCRUMBS_DEPTH,
is_breadcrumbs_depth(),
'最も深いカテゴリーを優先する'
);
// 設定項目の補足説明を表示
generate_tips_tag('複数のカテゴリーが選択されている場合、最も階層の深い(親が多い)カテゴリーを基点としてパンくずを表示します。');
?>
</td>
</tr>
`);
}
});
</script>
<?php
}
endif;
add_action('admin_menu', function() {
$hook = get_plugin_page_hook('theme-settings', 'theme-settings');
if ($hook) {
add_action($hook, 'add_breadcrumbs_setting');
}
}, 99);
if (!function_exists('is_breadcrumbs_depth')):
function is_breadcrumbs_depth() {
return get_theme_option(SINGLE_BREADCRUMBS_DEPTH, 0);
}
endif;
add_action('cocoon_settings_after_save', function() {
update_theme_option(SINGLE_BREADCRUMBS_DEPTH);
});