extras.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 Shoreditch
  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 shoreditch_body_classes( $classes ) {
  16. global $post;
  17. // Adds a class of group-blog to blogs with more than 1 published author.
  18. if ( is_multi_author() ) {
  19. $classes[] = 'group-blog';
  20. }
  21. // Adds a class of hfeed to non-singular pages.
  22. if ( ! is_singular() ) {
  23. $classes[] = 'hfeed';
  24. }
  25. // Adds a class of sticky-header to blogs with theme option turned on.
  26. if ( get_theme_mod( 'shoreditch_sticky_header' ) ) {
  27. $classes[] = 'sticky-header';
  28. }
  29. // Adds a class of no-sidebar to blogs without a sidebar or using a specific page template.
  30. if ( is_page_template( 'panel-page.php' ) || is_page_template( 'full-width-page.php' ) || is_singular( 'jetpack-testimonial' ) || ( is_post_type_archive( 'jetpack-testimonial' ) && have_posts() ) ) {
  31. $classes[] = 'no-sidebar';
  32. }
  33. // Adds a class of no-sidebar specifically to be used for Gutenberg styles, without interfering with the above.
  34. if ( ( ! is_page_template( 'panel-page.php' ) && ! is_page_template( 'full-width-page.php' ) )
  35. && ( ( is_home() || is_singular() || is_archive() )
  36. && ! is_active_sidebar( 'sidebar-1' ) ) ) {
  37. $classes[] = 'can-align-wide';
  38. }
  39. return $classes;
  40. }
  41. add_filter( 'body_class', 'shoreditch_body_classes' );
  42. /**
  43. * Add featured image as background image.
  44. */
  45. function shoreditch_background_image() {
  46. if ( 'post' === get_post_type() ) {
  47. $image = shoreditch_get_attachment_image_src( get_the_ID(), get_post_thumbnail_id( get_the_ID() ), 'post-thumbnail' );
  48. }
  49. else {
  50. $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'post-thumbnail' );
  51. $image = $image[0];
  52. }
  53. if ( ! $image ) {
  54. return;
  55. }
  56. printf( ' style="background-image: url(\'%s\');"', esc_url( $image ) );
  57. }
  58. /**
  59. * Modifies tag cloud widget arguments to have all tags in the widget same font size.
  60. *
  61. * @param array $args Arguments for tag cloud widget.
  62. * @return array A new modified arguments.
  63. */
  64. function shoreditch_widget_tag_cloud_args( $args ) {
  65. $args['largest'] = 1;
  66. $args['smallest'] = 1;
  67. $args['unit'] = 'em';
  68. return $args;
  69. }
  70. add_filter( 'widget_tag_cloud_args', 'shoreditch_widget_tag_cloud_args' );
  71. /**
  72. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  73. * @return string 'Continue reading' link prepended with an ellipsis.
  74. */
  75. if ( ! function_exists( 'shoreditch_excerpt_more' ) ) :
  76. function shoreditch_excerpt_more( $more ) {
  77. $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
  78. esc_url( get_permalink( get_the_ID() ) ),
  79. /* translators: %s: Name of current post. */
  80. sprintf( esc_html__( 'Continue reading %s', 'shoreditch' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  81. );
  82. return ' &hellip; ' . $link;
  83. }
  84. add_filter( 'excerpt_more', 'shoreditch_excerpt_more' );
  85. endif;