extras.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Libretto
  8. */
  9. /**
  10. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  11. *
  12. */
  13. function libretto_page_menu_args( $args ) {
  14. $args['show_home'] = true;
  15. return $args;
  16. }
  17. add_filter( 'wp_page_menu_args', 'libretto_page_menu_args' );
  18. /**
  19. * Adds custom classes to the array of body classes.
  20. * This class is used to distinguish blogs with multiple
  21. * authors from blogs with only one author.
  22. */
  23. function libretto_body_classes( $classes ) {
  24. // Adds a class of group-blog to blogs with more than 1 published author
  25. if ( is_multi_author() ) {
  26. $classes[] = 'group-blog';
  27. }
  28. // Adds a class if we're showing a header image on the page
  29. if ( ( libretto_has_post_thumbnail() && is_single() && libretto_jetpack_featured_image_display() ) ||
  30. ( has_post_thumbnail() && is_singular() && libretto_jetpack_featured_image_display() ) ||
  31. get_header_image() ) :
  32. $classes[] = 'libretto-has-header-image';
  33. endif;
  34. // Adds a class if we're on the homepage (blog index) in order to hide the header on mobile
  35. if ( is_home() ) :
  36. $classes[] = 'libretto-blog-home';
  37. endif;
  38. return $classes;
  39. }
  40. add_filter( 'body_class', 'libretto_body_classes' );
  41. /**
  42. * Adds custom classes to the array of post classes.
  43. * This serves to distinguish between "long form" post types
  44. * (standard, gallery, image, audio, video, and chat) and
  45. * "short form" post types, which are styled differently.
  46. * It also allows us to style posts with featured images a
  47. * little bit differently from those without.
  48. */
  49. function libretto_post_classes( $classes ) {
  50. if ( is_single() || is_page() || is_search() || is_archive() || is_front_page() || is_home() ) :
  51. // Check our post format to see if it should be styled as a long-form or short-form post
  52. $post_format = get_post_format();
  53. if ( 'aside' === $post_format || 'quote' === $post_format || 'link' === $post_format || 'status' === $post_format ) {
  54. $classes[] = 'libretto-short-form';
  55. } else {
  56. $classes[] = 'libretto-long-form';
  57. }
  58. endif;
  59. return $classes;
  60. }
  61. add_filter( 'post_class', 'libretto_post_classes' );
  62. /**
  63. * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
  64. *
  65. */
  66. function libretto_enhanced_image_navigation( $url, $id ) {
  67. if ( ! is_attachment() && ! wp_attachment_is_image( $id ) ) {
  68. return $url;
  69. }
  70. $image = get_post( $id );
  71. if ( ! empty( $image->post_parent ) && $image->post_parent !== $id ) {
  72. $url .= '#main';
  73. }
  74. return $url;
  75. }
  76. add_filter( 'attachment_link', 'libretto_enhanced_image_navigation', 10, 2 );