extras.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Penscratch 2
  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 penscratch_2_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. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  21. $classes[] = 'no-sidebar';
  22. }
  23. return $classes;
  24. }
  25. add_filter( 'body_class', 'penscratch_2_body_classes' );
  26. /**
  27. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  28. * @return string 'Continue reading' link prepended with an ellipsis.
  29. */
  30. if ( ! function_exists( 'penscratch_2_excerpt_more' ) ) :
  31. function penscratch_2_excerpt_more( $more ) {
  32. $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
  33. esc_url( get_permalink( get_the_ID() ) ),
  34. /* translators: %s: Name of current post */
  35. sprintf( esc_html__( 'Continue reading %s', 'penscratch-2' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  36. );
  37. return ' &hellip; ' . $link;
  38. }
  39. add_filter( 'excerpt_more', 'penscratch_2_excerpt_more' );
  40. endif;
  41. /**
  42. * Add a pingback url auto-discovery header for singularly identifiable articles.
  43. */
  44. function penscratch_2_pingback_header() {
  45. if ( is_singular() && pings_open() ) {
  46. echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
  47. }
  48. }
  49. add_action( 'wp_head', 'penscratch_2_pingback_header' );