Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is probably a trivia question, but I can't seem to find a simple solution.

This is my wp_list_caterories php...

<?php wp_list_categories(array(
    'orderby'   => 'name',
    'show_count'    => 1,
    'title_li'  => ''
)); ?>

This currently outputs this...

<li class="cat-item cat-item-1"><a href="http://example.com/category/uncategorized/" title="View all posts filed under Uncategorized">Uncategorized</a> (8)
</li>

I am trying to add this <span>&#124;</span> before my link so the final output looks like this...

<li class="cat-item cat-item-1"><span>&#124;</span><a href="http://example.com/category/uncategorized/" title="View all posts filed under Uncategorized">Uncategorized</a> (8)
</li>

Is it possible to do this within the PHP. I could do it using jquery but I'd rather use the PHP.

Many thanks for any help.

Josh

share|improve this question

1 Answer 1

up vote 0 down vote accepted

one possibility - add a filter to functions.php of your theme:

add_filter ( 'wp_list_categories', 'span_before_link_list_categories' );

function span_before_link_list_categories( $list ) {
$list = str_replace('<a href=','<span>&#124;</span><a href=',$list);
return $list;
}
share|improve this answer
    
This worked great thanks. Just out of interest. If I got wp_list_categories twice on the page, how do you target this function to a specific wp_list_categories. Again thank you!!! –  Joshc Jul 10 '12 at 9:57
    
unfortunately, that is not really possible. if you have access to one the wp_list_categories() codes, you could add the filter just before the code and remove it after the code. –  Michael Jul 10 '12 at 10:03
    
Yeah that worked perfect. Thank you very much! –  Joshc Jul 10 '12 at 13:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.