i making wordpress theme , want add different icons category. want if select music category while adding wordpress post there should music icon before category in single post. ( screenshot added)
if select image category there should image icon before category in single post page. using wordpress , saw work on wordpress theme:


i planning use font-awesome icons... here :)
apply filter on the_category hook modify html of the_category function , add class name. code obtained wordpress stackexchange answer.
function add_class_callback( $result ) { $class = strtolower( $result[2] ); $class = str_replace( ' ', '-', $class ); $replacement = sprintf( ' class=""><i class="fa %s"></i>%s</a>', $class, $result[2] ); return preg_replace( '#>([^<]+)</a>#uis', $replacement, $result[0] ); } function add_category_slug( $html ) { $search = '#<a[^>]+(\>([^<]+)\</a>)#uuis'; $html = preg_replace_callback( $search, 'add_class_callback', $html ); return $html; } add_filter( 'the_category', 'add_category_slug', 99, 1 ); the above function should add required markup. then, include following css in stylesheet.
.post-categories .music:before { content: "\f001"; }
Comments
Post a Comment