functions.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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(
  52. 'html5',
  53. array(
  54. 'search-form',
  55. 'comment-form',
  56. 'comment-list',
  57. 'gallery',
  58. 'caption',
  59. )
  60. );
  61. // Set up the WordPress core custom background feature.
  62. add_theme_support(
  63. 'custom-background',
  64. apply_filters(
  65. 'photos_custom_background_args',
  66. array(
  67. 'default-color' => 'ffffff',
  68. 'default-image' => '',
  69. )
  70. )
  71. );
  72. // Add theme support for selective refresh for widgets.
  73. add_theme_support( 'customize-selective-refresh-widgets' );
  74. /**
  75. * Add support for core custom logo.
  76. *
  77. * @link https://codex.wordpress.org/Theme_Logo
  78. */
  79. add_theme_support(
  80. 'custom-logo',
  81. array(
  82. 'height' => 360,
  83. 'width' => 720,
  84. 'flex-width' => true,
  85. 'flex-height' => true,
  86. 'header-text' => array(
  87. 'site-title',
  88. 'site-description',
  89. ),
  90. )
  91. );
  92. /* Gutenberg! */
  93. add_theme_support( 'align-wide' );
  94. // Add support for responsive embeds.
  95. add_theme_support( 'responsive-embeds' );
  96. add_theme_support(
  97. 'editor-color-palette',
  98. array(
  99. array(
  100. 'name' => esc_html__( 'red', 'photos' ),
  101. 'slug' => 'red',
  102. 'color' => '#d63031',
  103. ),
  104. array(
  105. 'name' => esc_html__( 'charcoal', 'photos' ),
  106. 'slug' => 'charcoal',
  107. 'color' => '#111',
  108. ),
  109. array(
  110. 'name' => esc_html__( 'very light gray', 'photos' ),
  111. 'slug' => 'very-light-gray',
  112. 'color' => '#f0f0f0',
  113. ),
  114. array(
  115. 'name' => esc_html__( 'very dark gray', 'photos' ),
  116. 'slug' => 'very-dark-gray',
  117. 'color' => '#404040',
  118. ),
  119. array(
  120. 'name' => esc_html__( 'medium gray', 'photos' ),
  121. 'slug' => 'medium-gray',
  122. 'color' => '#606060',
  123. ),
  124. )
  125. );
  126. }
  127. endif;
  128. add_action( 'after_setup_theme', 'photos_setup' );
  129. /**
  130. * Set posts per page on theme switch
  131. */
  132. function photos_setup_options() {
  133. // Set the number of posts to display per page
  134. update_option( 'posts_per_page', 12 );
  135. }
  136. add_action( 'after_switch_theme', 'photos_setup_options' );
  137. /**
  138. * Set the content width in pixels, based on the theme's design and stylesheet.
  139. *
  140. * Priority 0 to make it available to lower priority callbacks.
  141. *
  142. * @global int $content_width
  143. */
  144. function photos_content_width() {
  145. // This variable is intended to be overruled from themes.
  146. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  147. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  148. $GLOBALS['content_width'] = apply_filters( 'photos_content_width', 640 );
  149. }
  150. add_action( 'after_setup_theme', 'photos_content_width', 0 );
  151. /**
  152. * Register widget area.
  153. *
  154. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  155. */
  156. function photos_widgets_init() {
  157. register_sidebar(
  158. array(
  159. 'name' => esc_html__( 'Footer', 'photos' ),
  160. 'id' => 'sidebar-1',
  161. 'description' => esc_html__( 'These widgets will be displayed at the bottom of each page.', 'photos' ),
  162. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  163. 'after_widget' => '</section>',
  164. 'before_title' => '<h2 class="widget-title">',
  165. 'after_title' => '</h2>',
  166. )
  167. );
  168. }
  169. add_action( 'widgets_init', 'photos_widgets_init' );
  170. /**
  171. * Enqueue scripts and styles.
  172. */
  173. function photos_scripts() {
  174. // Main stylesheet
  175. wp_enqueue_style( 'photos-style', get_stylesheet_uri() );
  176. // Gutenberg styles
  177. wp_enqueue_style( 'photos-blocks', get_template_directory_uri() . '/blocks.css' );
  178. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  179. wp_enqueue_script( 'comment-reply' );
  180. }
  181. wp_enqueue_script( 'photos-global', get_theme_file_uri( '/js/global.js' ), array( 'jquery' ), '20180724', true );
  182. wp_enqueue_script( 'photos-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
  183. $photos_l10n = array();
  184. wp_enqueue_script( 'photos-navigation', get_theme_file_uri( '/js/navigation.js' ), array( 'jquery' ), '1.0', true );
  185. $photos_l10n['expand'] = esc_attr__( 'Expand child menu', 'photos' );
  186. $photos_l10n['collapse'] = esc_attr__( 'Collapse child menu', 'photos' );
  187. $photos_l10n['icon'] = photos_get_svg(
  188. array(
  189. 'icon' => 'expand',
  190. 'fallback' => true,
  191. )
  192. );
  193. wp_localize_script( 'photos-navigation', 'photosScreenReaderText', $photos_l10n );
  194. }
  195. add_action( 'wp_enqueue_scripts', 'photos_scripts' );
  196. /**
  197. * Gutenberg Editor Styles
  198. */
  199. function photos_editor_styles() {
  200. wp_enqueue_style( 'photos-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  201. }
  202. add_action( 'enqueue_block_editor_assets', 'photos_editor_styles' );
  203. /**
  204. * Custom template tags for this theme.
  205. */
  206. require get_template_directory() . '/inc/template-tags.php';
  207. /**
  208. * Functions which enhance the theme by hooking into WordPress.
  209. */
  210. require get_template_directory() . '/inc/template-functions.php';
  211. /**
  212. * Customizer additions.
  213. */
  214. require get_template_directory() . '/inc/customizer.php';
  215. /**
  216. * Logo Resizer: Bringing logo resizing to the Customizer.
  217. */
  218. require get_template_directory() . '/inc/logo-resizer.php';
  219. /**
  220. * Load Jetpack compatibility file.
  221. */
  222. require get_template_directory() . '/inc/jetpack.php';
  223. /**
  224. * Load Custom Header funtionality.
  225. */
  226. require get_template_directory() . '/inc/custom-header.php';
  227. /**
  228. * SVG icons functions and filters.
  229. */
  230. require get_template_directory() . '/inc/icon-functions.php';