extras.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Custom functions that act independently of the theme templates
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features
  6. *
  7. * @package bml
  8. */
  9. /**
  10. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  11. */
  12. function bml_page_menu_args( $args ) {
  13. $args['show_home'] = true;
  14. return $args;
  15. }
  16. add_filter( 'wp_page_menu_args', 'bml_page_menu_args' );
  17. /**
  18. * Adds custom classes to the array of body classes.
  19. */
  20. function bml_body_classes( $classes ) {
  21. // Adds a class of group-blog to blogs with more than 1 published author
  22. if ( is_multi_author() ) {
  23. $classes[] = 'group-blog';
  24. }
  25. return $classes;
  26. }
  27. add_filter( 'body_class', 'bml_body_classes' );
  28. /**
  29. * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
  30. */
  31. function bml_enhanced_image_navigation( $url, $id ) {
  32. if ( ! is_attachment() && ! wp_attachment_is_image( $id ) )
  33. return $url;
  34. $image = get_post( $id );
  35. if ( ! empty( $image->post_parent ) && $image->post_parent != $id )
  36. $url .= '#main';
  37. return $url;
  38. }
  39. add_filter( 'attachment_link', 'bml_enhanced_image_navigation', 10, 2 );
  40. /**
  41. * Filters wp_title to print a neat <title> tag based on what is being viewed.
  42. */
  43. function bml_wp_title( $title, $sep ) {
  44. global $page, $paged;
  45. if ( is_feed() )
  46. return $title;
  47. // Add the blog name
  48. $title .= get_bloginfo( 'name' );
  49. // Add the blog description for the home/front page.
  50. $site_description = get_bloginfo( 'description', 'display' );
  51. if ( $site_description && ( is_home() || is_front_page() ) )
  52. $title .= " $sep $site_description";
  53. // Add a page number if necessary:
  54. if ( $paged >= 2 || $page >= 2 )
  55. $title .= " $sep " . sprintf( __( 'Page %s', 'bml' ), max( $paged, $page ) );
  56. return $title;
  57. }
  58. add_filter( 'wp_title', 'bml_wp_title', 10, 2 );