/*
* エントリー内のID属性の先頭にエントリー番号をつけます
*/
function prefix_entry_number_to_id($content) {
global $id;
if ( is_single() || is_page() ) {
// individualな場合は実行しない
return $content;
}
$content = preg_replace(
'/(<[^>]*\s)id="(.+?)"/',
'\1id="entry'. $id. '-\2"',
$content
);
$content = preg_replace(
'/(<[^>]*\s)href="#(.+?)"/',
'\1href="'. get_permalink(). '#\2"',
$content
);
return $content;
}
add_action('the_content', prefix_entry_number_to_id, 100);
entryxxの部分にエントリーの番号を入れたいのだけれどどうやれば取得できるのか。うーん。
上記問題解決です。グローバル変数 $id で取得できました。ついでに目次などのページ内リンクの前にパーマリンクの URL を入れるように変更。