functions.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * Photos functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package photos
  8. */
  9. if ( ! function_exists( 'photos_setup' ) ) :
  10. /**
  11. * Sets up theme defaults and registers support for various WordPress features.
  12. *
  13. * Note that this function is hooked into the after_setup_theme hook, which
  14. * runs before the init hook. The init hook is too late for some features, such
  15. * as indicating support for post thumbnails.
  16. */
  17. function photos_setup() {
  18. /*
  19. * Make theme available for translation.
  20. * Translations can be filed in the /languages/ directory.
  21. * If you're building a theme based on Photos, use a find and replace
  22. * to change 'photos' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'photos', get_template_directory() . '/languages' );
  25. // Add default posts and comments RSS feed links to head.
  26. add_theme_support( 'automatic-feed-links' );
  27. /*
  28. * Let WordPress manage the document title.
  29. * By adding theme support, we declare that this theme does not use a
  30. * hard-coded <title> tag in the document head, and expect WordPress to
  31. * provide it for us.
  32. */
  33. add_theme_support( 'title-tag' );
  34. /*
  35. * Enable support for Post Thumbnails on posts and pages.
  36. *
  37. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  38. */
  39. add_theme_support( 'post-thumbnails' );
  40. set_post_thumbnail_size( 320, 320, true );
  41. // Home page thumbnails
  42. // Double-sized for retina
  43. add_image_size( 'photos-grid-thumb', 640, 640, true );
  44. add_image_size( 'photos-featured', 2040, 9999, false );
  45. // This theme uses wp_nav_menu() in one location.
  46. register_nav_menu( 'menu-1', esc_html__( 'Primary', 'photos' ) );
  47. /*
  48. * Switch default core markup for search form, comment form, and comments
  49. * to output valid HTML5.
  50. */
  51. add_theme_support( 'html5', array(
  52. 'search-form',
  53. 'comment-form',
  54. 'comment-list',
  55. 'gallery',
  56. 'caption',
  57. ) );
  58. // Set up the WordPress core custom background feature.
  59. add_theme_support( 'custom-background', apply_filters( 'photos_custom_background_args', array(
  60. 'default-color' => 'ffffff',
  61. 'default-image' => '',
  62. ) ) );
  63. // Add theme support for selective refresh for widgets.
  64. add_theme_support( 'customize-selective-refresh-widgets' );
  65. /**
  66. * Add support for core custom logo.
  67. *
  68. * @link https://codex.wordpress.org/Theme_Logo
  69. */
  70. add_theme_support( 'custom-logo', array(
  71. 'height' => 360,
  72. 'width' => 720,
  73. 'flex-width' => true,
  74. 'flex-height' => true,
  75. 'header-text' => array(
  76. 'site-title',
  77. 'site-description',
  78. ),
  79. ) );
  80. /* Gutenberg! */
  81. add_theme_support( 'align-wide' );
  82. // Add support for responsive embeds.
  83. add_theme_support( 'responsive-embeds' );
  84. add_theme_support( 'editor-color-palette', array(
  85. array(
  86. 'name' => esc_html__( 'red', 'photos' ),
  87. 'slug' => 'red',
  88. 'color' => '#d63031',
  89. ),
  90. array(
  91. 'name' => esc_html__( 'charcoal', 'photos' ),
  92. 'slug' => 'charcoal',
  93. 'color' => '#111',
  94. ),
  95. array(
  96. 'name' => esc_html__( 'very light gray', 'photos' ),
  97. 'slug' => 'very-light-gray',
  98. 'color' => '#f0f0f0',
  99. ),
  100. array(
  101. 'name' => esc_html__( 'very dark gray', 'photos' ),
  102. 'slug' => 'very-dark-gray',
  103. 'color' => '#404040',
  104. ),
  105. array(
  106. 'name' => esc_html__( 'medium gray', 'photos' ),
  107. 'slug' => 'medium-gray',
  108. 'color' => '#606060',
  109. )
  110. ) );
  111. }
  112. endif;
  113. add_action( 'after_setup_theme', 'photos_setup' );
  114. /**
  115. * Set posts per page on theme switch
  116. */
  117. function photos_setup_options() {
  118. // Set the number of posts to display per page
  119. update_option( 'posts_per_page', 12 );
  120. }
  121. add_action( 'after_switch_theme', 'photos_setup_options' );
  122. /**
  123. * Set the content width in pixels, based on the theme's design and stylesheet.
  124. *
  125. * Priority 0 to make it available to lower priority callbacks.
  126. *
  127. * @global int $content_width
  128. */
  129. function photos_content_width() {
  130. // This variable is intended to be overruled from themes.
  131. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  132. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  133. $GLOBALS['content_width'] = apply_filters( 'photos_content_width', 640 );
  134. }
  135. add_action( 'after_setup_theme', 'photos_content_width', 0 );
  136. /**
  137. * Register widget area.
  138. *
  139. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  140. */
  141. function photos_widgets_init() {
  142. register_sidebar( array(
  143. 'name' => esc_html__( 'Footer', 'photos' ),
  144. 'id' => 'sidebar-1',
  145. 'description' => esc_html__( 'These widgets will be displayed at the bottom of each page.', 'photos' ),
  146. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  147. 'after_widget' => '</section>',
  148. 'before_title' => '<h2 class="widget-title">',
  149. 'after_title' => '</h2>',
  150. ) );
  151. }
  152. add_action( 'widgets_init', 'photos_widgets_init' );
  153. /**
  154. * Enqueue scripts and styles.
  155. */
  156. function photos_scripts() {
  157. // Main stylesheet
  158. wp_enqueue_style( 'photos-style', get_stylesheet_uri() );
  159. // Gutenberg styles
  160. wp_enqueue_style( 'photos-blocks', get_template_directory_uri() . '/blocks.css' );
  161. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  162. wp_enqueue_script( 'comment-reply' );
  163. }
  164. wp_enqueue_script( 'photos-global', get_theme_file_uri( '/js/global.js' ), array( 'jquery' ), '20180724', true );
  165. wp_enqueue_script( 'photos-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
  166. $photos_l10n = array();
  167. wp_enqueue_script( 'photos-navigation', get_theme_file_uri( '/js/navigation.js' ), array( 'jquery' ), '1.0', true );
  168. $photos_l10n['expand'] = esc_attr__( 'Expand child menu', 'photos' );
  169. $photos_l10n['collapse'] = esc_attr__( 'Collapse child menu', 'photos' );
  170. $photos_l10n['icon'] = photos_get_svg( array( 'icon' => 'expand', 'fallback' => true ) );
  171. wp_localize_script( 'photos-navigation', 'photosScreenReaderText', $photos_l10n );
  172. }
  173. add_action( 'wp_enqueue_scripts', 'photos_scripts' );
  174. /**
  175. * Gutenberg Editor Styles
  176. */
  177. function photos_editor_styles() {
  178. wp_enqueue_style( 'photos-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  179. }
  180. add_action( 'enqueue_block_editor_assets', 'photos_editor_styles' );
  181. /**
  182. * Custom template tags for this theme.
  183. */
  184. require get_template_directory() . '/inc/template-tags.php';
  185. /**
  186. * Functions which enhance the theme by hooking into WordPress.
  187. */
  188. require get_template_directory() . '/inc/template-functions.php';
  189. /**
  190. * Customizer additions.
  191. */
  192. require get_template_directory() . '/inc/customizer.php';
  193. /**
  194. * Logo Resizer: Bringing logo resizing to the Customizer.
  195. */
  196. require get_template_directory() . '/inc/logo-resizer.php';
  197. /**
  198. * Load Jetpack compatibility file.
  199. */
  200. require get_template_directory() . '/inc/jetpack.php';
  201. /**
  202. * Load Custom Header funtionality.
  203. */
  204. require get_template_directory() . '/inc/custom-header.php';
  205. /**
  206. * SVG icons functions and filters.
  207. */
  208. require get_template_directory() . '/inc/icon-functions.php';