Advertisement
Guest User

Wordpress wrap all vowels in the_title within <span> tags

a guest
Sep 12th, 2010
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. function str_replace_assoc(array $replace, $subject) {
  2.    return str_ireplace(array_keys($replace), array_values($replace), $subject);  
  3. };
  4.  
  5. function title_wrap_vowels($items) {
  6.  
  7. $vowelreplace = array(
  8. 'a' => '<span>a</span>',
  9. 'e' => '<span>e</span>',
  10. 'i' => '<span>i</span>',
  11. 'o' => '<span>o</span>',
  12. 'u' => '<span>u</span>',
  13. );
  14.  
  15. return str_replace_assoc($vowelreplace, $items);
  16. };
  17.  
  18. function title_wrap_vowels_menu($item_output, $item, $depth, $args) {
  19.  
  20. global $wp_query;
  21. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  22.  
  23. $class_names = $value = '';
  24.  
  25. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  26. $classes[] = 'menu-item-' . $item->ID;
  27.  
  28. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  29. $class_names = ' class="' . esc_attr( $class_names ) . '"';
  30.  
  31. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  32. $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  33.  
  34. $output .= $indent . '<li' . $id . $value . $class_names .'>';
  35.  
  36. $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  37. $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  38. $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  39. $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  40.  
  41. $item_output = $args->before;
  42.         $item_output .= '<a'. $attributes .'>';
  43.         @h@$item_output .= $args->link_before . title_wrap_vowels(apply_filters( 'the_title', $item->title, $item->ID )) . $args->link_after;
  44.         $item_output .= '</a>';
  45.         $item_output .= $args->after;
  46.     return $item_output;
  47.  
  48. }
  49. add_filter('walker_nav_menu_start_el','title_wrap_vowels_menu', 1, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement