jetpack.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. *
  5. * @link https://jetpack.com/
  6. *
  7. * @package photos
  8. */
  9. /**
  10. * Jetpack setup function.
  11. *
  12. * See: https://jetpack.com/support/infinite-scroll/
  13. * See: https://jetpack.com/support/responsive-videos/
  14. * See: https://jetpack.com/support/content-options/
  15. */
  16. function photos_jetpack_setup() {
  17. // Add theme support for Infinite Scroll.
  18. add_theme_support( 'infinite-scroll', array(
  19. 'container' => 'main',
  20. 'footer' => 'page',
  21. 'footer_widgets' => array(
  22. 'sidebar-1',
  23. 'sidebar-2',
  24. 'sidebar-3' ),
  25. 'posts_per_page' => 12,
  26. 'render' => 'photos_infinite_scroll_render',
  27. 'type' => 'scroll',
  28. 'wrapper' => false,
  29. ) );
  30. // Add theme support for Responsive Videos.
  31. add_theme_support( 'jetpack-responsive-videos' );
  32. // Add theme support for Content Options.
  33. add_theme_support( 'jetpack-content-options', array(
  34. 'post-details' => array(
  35. 'stylesheet' => 'photos-style',
  36. 'date' => '.posted-on',
  37. 'categories' => '.cat-links',
  38. 'tags' => '.tags-links',
  39. 'author' => '.byline',
  40. ),
  41. 'featured-images' => array(
  42. 'archive' => true,
  43. 'post' => true,
  44. 'post-default' => false,
  45. 'page' => true,
  46. 'page-default' => false,
  47. 'fallback' => true,
  48. ),
  49. ) );
  50. // Social Menu
  51. add_theme_support( 'jetpack-social-menu', 'svg' );
  52. }
  53. add_action( 'after_setup_theme', 'photos_jetpack_setup' );
  54. /**
  55. * Custom render function for Infinite Scroll.
  56. */
  57. function photos_infinite_scroll_render() {
  58. while ( have_posts() ) {
  59. the_post();
  60. get_template_part( 'template-parts/content', 'grid' );
  61. }
  62. }
  63. /**
  64. * Social menu
  65. */
  66. function photos_social_menu() {
  67. if ( function_exists( 'jetpack_social_menu' ) ) {
  68. jetpack_social_menu();
  69. }
  70. }
  71. /**
  72. * Custom function to check for a post thumbnail;
  73. * If Jetpack is not available, fall back to has_post_thumbnail()
  74. */
  75. function photos_has_post_thumbnail( $post = null ) {
  76. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  77. return jetpack_has_featured_image( $post );
  78. } else {
  79. return has_post_thumbnail( $post );
  80. }
  81. }
  82. /**
  83. *
  84. */
  85. function photos_relatedposts_filter_thumbnail_size() {
  86. $size = array(
  87. 'width' => 320,
  88. 'height' => 320
  89. );
  90. return $size;
  91. }
  92. add_filter( 'jetpack_relatedposts_filter_thumbnail_size', 'photos_relatedposts_filter_thumbnail_size' );
  93. /**
  94. * Removing related posts from default spot below the post content
  95. */
  96. function photos_remove_related_posts() {
  97. if ( class_exists( 'Jetpack_RelatedPosts' ) ) {
  98. $jprp = Jetpack_RelatedPosts::init();
  99. $callback = array( $jprp, 'filter_add_target_to_dom' );
  100. remove_filter( 'the_content', $callback, 40 );
  101. }
  102. }
  103. // add_filter( 'wp', 'photos_remove_related_posts', 20 );
  104. /**
  105. * This function is used to add related posts where we want them
  106. */
  107. function photos_related_posts() {
  108. if ( class_exists( 'Jetpack_RelatedPosts' ) ) {
  109. echo do_shortcode( '[jetpack-related-posts]' );
  110. }
  111. }