extras.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Toujours
  8. */
  9. /**
  10. * Adds custom classes to the array of body classes.
  11. *
  12. * @param array $classes Classes for the body element.
  13. * @return array
  14. */
  15. function toujours_body_classes( $classes ) {
  16. // Adds a class of group-blog to blogs with more than 1 published author.
  17. if ( is_multi_author() ) {
  18. $classes[] = 'group-blog';
  19. }
  20. // Adds a class of hfeed to non-singular pages.
  21. if ( ! is_singular() ) {
  22. $classes[] = 'hfeed';
  23. }
  24. // Adds a class when sidebar widget is unused
  25. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  26. $classes[] = 'no-sidebar';
  27. }
  28. // Adds class if user has added custom background image
  29. // Allows default background pattern to be retina
  30. $bgimage = get_background_image();
  31. $bgimage = basename( $bgimage ); //Get the background's filename
  32. if ( 'toujoursbackground20160105.png' !== $bgimage ) {
  33. $classes[] = 'user-background';
  34. }
  35. // Add a class if has custom header image
  36. $header_image = get_header_image();
  37. if ( ! empty( $header_image ) ) {
  38. $classes[] = 'has-header-image';
  39. }
  40. // Add class if featured image borders hidden
  41. if ( false === get_theme_mod( 'toujours_featured_image_borders', true ) ) {
  42. $classes[] = 'hide-featured-image-borders';
  43. }
  44. return $classes;
  45. }
  46. add_filter( 'body_class', 'toujours_body_classes' );
  47. /**
  48. * Remove the 1st gallery shortcode from gallery post format content.
  49. */
  50. function toujours_strip_first_gallery( $content ) {
  51. if ( 'gallery' === get_post_format() && 'post' === get_post_type() && get_post_gallery() ) {
  52. $regex = get_shortcode_regex( array( 'gallery' ) );
  53. $content = preg_replace( '/'. $regex .'/s', '', $content, 1 );
  54. $content = wp_kses_post( $content );
  55. }
  56. return $content;
  57. }
  58. add_filter( 'the_content', 'toujours_strip_first_gallery' );