twentysixteen.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: http://jetpack.com/
  5. */
  6. function twentysixteen_jetpack_setup() {
  7. /**
  8. * Add theme support for Responsive Videos.
  9. */
  10. add_theme_support( 'jetpack-responsive-videos' );
  11. /**
  12. * Add theme support for geo-location.
  13. */
  14. add_theme_support( 'jetpack-geo-location' );
  15. }
  16. add_action( 'after_setup_theme', 'twentysixteen_jetpack_setup' );
  17. function twentysixteen_init_jetpack() {
  18. /**
  19. * Add our compat CSS file for custom widget stylings and such.
  20. * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production
  21. * or skip it entirely for wpcom.
  22. */
  23. if ( ! is_admin() ) {
  24. $version = false;
  25. if ( method_exists( 'Jetpack', 'is_development_version' ) ) {
  26. $version = Jetpack::is_development_version() ? filemtime( plugin_dir_path( __FILE__ ) . 'twentysixteen.css' ) : JETPACK__VERSION;
  27. }
  28. wp_enqueue_style( 'twentysixteen-jetpack', plugins_url( 'twentysixteen.css', __FILE__ ), array(), $version );
  29. wp_style_add_data( 'twentysixteen-jetpack', 'rtl', 'replace' );
  30. }
  31. }
  32. add_action( 'init', 'twentysixteen_init_jetpack' );
  33. /**
  34. * Alter gallery widget default width.
  35. */
  36. function twentysixteen_gallery_widget_content_width( $width ) {
  37. return 390;
  38. }
  39. add_filter( 'gallery_widget_content_width', 'twentysixteen_gallery_widget_content_width' );
  40. /**
  41. * Remove ratings from excerpts that are used as intro on blog index, single, and archive pages.
  42. */
  43. function twentysixteen_remove_share() {
  44. if ( is_single() || is_archive() || is_home() ) {
  45. remove_filter( 'the_excerpt', 'sharing_display', 19 );
  46. if ( class_exists( 'Jetpack_Likes' ) ) {
  47. remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
  48. }
  49. }
  50. }
  51. add_action( 'loop_start', 'twentysixteen_remove_share' );
  52. function twentysixteen_jetpack_lazy_images_compat() {
  53. if ( ! function_exists( 'wp_add_inline_script' ) ) {
  54. return;
  55. }
  56. // Since TwentySixteen outdents when window is resized, let's trigger a window resize
  57. // every time we lazy load an image on the TwentySixteen theme.
  58. wp_add_inline_script(
  59. 'jetpack-lazy-images',
  60. "jQuery( document.body ).on( 'jetpack-lazy-loaded-image', function () { jQuery( window ).trigger( 'resize' ); } );"
  61. );
  62. }
  63. // Priority needs to be 11 here so that we have already enqueued jetpack-lazy-images.
  64. add_action( 'wp_enqueue_scripts', 'twentysixteen_jetpack_lazy_images_compat', 11 );