extras.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Sketch
  8. */
  9. /**
  10. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  11. *
  12. * @param array $args Configuration arguments.
  13. * @return array
  14. */
  15. function sketch_page_menu_args( $args ) {
  16. $args['show_home'] = true;
  17. return $args;
  18. }
  19. add_filter( 'wp_page_menu_args', 'sketch_page_menu_args' );
  20. /**
  21. * Adds custom classes to the array of body classes.
  22. *
  23. * @param array $classes Classes for the body element.
  24. * @return array
  25. */
  26. function sketch_body_classes( $classes ) {
  27. // Adds a class of group-blog to blogs with more than 1 published author.
  28. if ( is_multi_author() ) {
  29. $classes[] = 'group-blog';
  30. }
  31. if ( function_exists( 'jetpack_has_site_logo' ) && jetpack_has_site_logo() ) {
  32. $classes[] = 'has-site-logo';
  33. }
  34. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  35. $classes[] = 'no-sidebar';
  36. }
  37. return $classes;
  38. }
  39. add_filter( 'body_class', 'sketch_body_classes' );
  40. /**
  41. * Filters wp_title to print a neat <title> tag based on what is being viewed.
  42. *
  43. * @param string $title Default title text for current view.
  44. * @param string $sep Optional separator.
  45. * @return string The filtered title.
  46. */
  47. function sketch_wp_title( $title, $sep ) {
  48. if ( is_feed() ) {
  49. return $title;
  50. }
  51. global $page, $paged;
  52. // Add the blog name
  53. $title .= get_bloginfo( 'name', 'display' );
  54. // Add the blog description for the home/front page.
  55. $site_description = get_bloginfo( 'description', 'display' );
  56. if ( $site_description && ( is_home() || is_front_page() ) ) {
  57. $title .= " $sep $site_description";
  58. }
  59. // Add a page number if necessary:
  60. if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
  61. $title .= " $sep " . sprintf( __( 'Page %s', 'sketch' ), max( $paged, $page ) );
  62. }
  63. return $title;
  64. }
  65. add_filter( 'wp_title', 'sketch_wp_title', 10, 2 );
  66. /**
  67. * Sets the authordata global when viewing an author archive.
  68. *
  69. * This provides backwards compatibility with
  70. * http://core.trac.wordpress.org/changeset/25574
  71. *
  72. * It removes the need to call the_post() and rewind_posts() in an author
  73. * template to print information about the author.
  74. *
  75. * @global WP_Query $wp_query WordPress Query object.
  76. * @return void
  77. */
  78. function sketch_setup_author() {
  79. global $wp_query;
  80. if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
  81. $GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
  82. }
  83. }
  84. add_action( 'wp', 'sketch_setup_author' );