Wordpress - Last class on category navigation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ----------------------------------------------
  2. Functions.php
  3. ----------------------------------------------
  4.  
  5. function add_last_class($input) {
  6. if( !empty($input) ) {
  7.  
  8. $pattern = '/<li class="(?!.*<li class=")/is';
  9. $replacement = '<li class="last ';
  10.  
  11. $input = preg_replace($pattern, $replacement, $input);
  12.  
  13. echo $input;
  14. }
  15. }
  16.  
  17. ----------------------------------------------
  18. Header.php
  19.  
  20. Need to put echo=0 for it to work when calling
  21. this function
  22. ----------------------------------------------
  23.  
  24.  
  25. <?php add_last_class(wp_list_categories('title_li=&echo=0'));?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.