Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
Last active March 27, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mypacecreator/dfdaeb7fb0578136d1af991c26490a4e to your computer and use it in GitHub Desktop.
Save mypacecreator/dfdaeb7fb0578136d1af991c26490a4e to your computer and use it in GitHub Desktop.
wp_list_categories の出力で、カレント表示のclass名の変更と、a要素の内側にさらにspanを入れる
<?php
/**
* wp_list_categories の出力を支給HTMLに合わせて変更
* カレント表示のclass変更、a要素の内側にさらにspanを入れる
*
* @param string $output
*
* @return string
*/
function my_wp_list_categories( $output ) {
$output = preg_replace( '/current-cat/', 'on', $output );
$output = preg_replace( '/<a href="(.+?)" >(.+?)<\/a>/', '<a href="$1"><span>$2</span></a>', $output );
return $output;
}
add_filter( 'wp_list_categories', 'my_wp_list_categories' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment