functions.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /**
  3. * Gazette functions and definitions
  4. *
  5. * @package Gazette
  6. */
  7. /**
  8. * Set the content width based on the theme's design and stylesheet.
  9. */
  10. if ( ! isset( $content_width ) ) {
  11. $content_width = 720; /* pixels */
  12. }
  13. if ( ! function_exists( 'gazette_content_width' ) ) {
  14. function gazette_content_width() {
  15. global $content_width;
  16. if ( is_page() ) {
  17. $content_width = 869;
  18. }
  19. }
  20. }
  21. add_action( 'template_redirect', 'gazette_content_width' );
  22. if ( ! function_exists( 'gazette_setup' ) ) :
  23. /**
  24. * Sets up theme defaults and registers support for various WordPress features.
  25. *
  26. * Note that this function is hooked into the after_setup_theme hook, which
  27. * runs before the init hook. The init hook is too late for some features, such
  28. * as indicating support for post thumbnails.
  29. */
  30. function gazette_setup() {
  31. /*
  32. * Make theme available for translation.
  33. * Translations can be filed in the /languages/ directory.
  34. * If you're building a theme based on Gazette, use a find and replace
  35. * to change 'gazette' to the name of your theme in all the template files
  36. */
  37. load_theme_textdomain( 'gazette', get_template_directory() . '/languages' );
  38. // Add default posts and comments RSS feed links to head.
  39. add_theme_support( 'automatic-feed-links' );
  40. /*
  41. * Let WordPress manage the document title.
  42. * By adding theme support, we declare that this theme does not use a
  43. * hard-coded <title> tag in the document head, and expect WordPress to
  44. * provide it for us.
  45. */
  46. add_theme_support( 'title-tag' );
  47. /*
  48. * Enable support for Post Thumbnails on posts and pages.
  49. *
  50. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  51. */
  52. add_theme_support( 'post-thumbnails' );
  53. add_image_size( 'gazette-post-thumbnail', 720, 426, true );
  54. add_image_size( 'gazette-post-thumbnail-square', 720, 720, true );
  55. add_image_size( 'gazette-featured-content-thumbnail', 960, 540, true );
  56. add_image_size( 'gazette-single-thumbnail', 1920, 768, true );
  57. // This theme uses wp_nav_menu() in two locations.
  58. register_nav_menus( array(
  59. 'primary' => __( 'Primary Location', 'gazette' ),
  60. 'social' => __( 'Social Location', 'gazette' ),
  61. ) );
  62. /*
  63. * Switch default core markup for search form, comment form, and comments
  64. * to output valid HTML5.
  65. */
  66. add_theme_support( 'html5', array(
  67. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
  68. ) );
  69. /*
  70. * Enable support for Post Formats.
  71. * See http://codex.wordpress.org/Post_Formats
  72. */
  73. add_theme_support( 'post-formats', array(
  74. 'image', 'video', 'link', 'gallery',
  75. ) );
  76. // Add support for responsive embeds.
  77. add_theme_support( 'responsive-embeds' );
  78. // Add support for custom color scheme.
  79. add_theme_support( 'editor-color-palette', array(
  80. array(
  81. 'name' => esc_html__( 'Blue', 'gazette' ),
  82. 'slug' => 'blue',
  83. 'color' => '#3863c1',
  84. ),
  85. array(
  86. 'name' => esc_html__( 'Dark Gray', 'gazette' ),
  87. 'slug' => 'dark-gray',
  88. 'color' => '#222',
  89. ),
  90. array(
  91. 'name' => esc_html__( 'Medium Gray', 'gazette' ),
  92. 'slug' => 'medium-gray',
  93. 'color' => '#777',
  94. ),
  95. array(
  96. 'name' => esc_html__( 'Light Gray', 'gazette' ),
  97. 'slug' => 'light-gray',
  98. 'color' => '#ddd',
  99. ),
  100. array(
  101. 'name' => esc_html__( 'White', 'gazette' ),
  102. 'slug' => 'white',
  103. 'color' => '#fff',
  104. ),
  105. ) );
  106. }
  107. endif; // gazette_setup
  108. add_action( 'after_setup_theme', 'gazette_setup' );
  109. /**
  110. * Register widget area.
  111. *
  112. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  113. */
  114. function gazette_widgets_init() {
  115. register_sidebar( array(
  116. 'name' => __( 'Sidebar', 'gazette' ),
  117. 'id' => 'sidebar-1',
  118. 'description' => '',
  119. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  120. 'after_widget' => '</aside>',
  121. 'before_title' => '<h2 class="widget-title">',
  122. 'after_title' => '</h2>',
  123. ) );
  124. register_sidebar( array(
  125. 'name' => __( 'Footer', 'gazette' ),
  126. 'id' => 'sidebar-2',
  127. 'description' => '',
  128. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  129. 'after_widget' => '</aside>',
  130. 'before_title' => '<h2 class="widget-title">',
  131. 'after_title' => '</h2>',
  132. ) );
  133. }
  134. add_action( 'widgets_init', 'gazette_widgets_init' );
  135. /**
  136. * Register Lato and Inconsolata fonts.
  137. *
  138. * @return string
  139. */
  140. function gazette_lato_inconsolata_fonts_url() {
  141. $fonts_url = '';
  142. /* translators: If there are characters in your language that are not supported
  143. * by Lato, translate this to 'off'. Do not translate into your own language.
  144. */
  145. $lato = _x( 'on', 'Lato font: on or off', 'gazette' );
  146. /* translators: If there are characters in your language that are not supported
  147. * by Inconsolata, translate this to 'off'. Do not translate into your own language.
  148. */
  149. $inconsolata = _x( 'on', 'Inconsolata font: on or off', 'gazette' );
  150. if ( 'off' !== $lato || 'off' !== $inconsolata ) {
  151. $font_families = array();
  152. if ( 'off' !== $lato ) {
  153. $font_families[] = 'Lato:400,700,900,400italic,700italic,900italic';
  154. }
  155. if ( 'off' !== $inconsolata ) {
  156. $font_families[] = 'Inconsolata:400,700';
  157. }
  158. $query_args = array(
  159. 'family' => urlencode( implode( '|', $font_families ) ),
  160. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  161. );
  162. $fonts_url = add_query_arg( $query_args, "https://fonts.googleapis.com/css" );
  163. }
  164. return $fonts_url;
  165. }
  166. /**
  167. * Register Lora font.
  168. *
  169. * @return string
  170. */
  171. function gazette_lora_font_url() {
  172. $lora_font_url = '';
  173. /* translators: If there are characters in your language that are not supported
  174. * by Lora, translate this to 'off'. Do not translate into your own language.
  175. */
  176. if ( 'off' !== _x( 'on', 'Lora font: on or off', 'gazette' ) ) {
  177. $query_args = array(
  178. 'family' => urlencode( 'Lora:400,700,400italic,700italic' ),
  179. 'subset' => urlencode( 'latin,latin-ext' ),
  180. );
  181. $lora_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  182. }
  183. return $lora_font_url;
  184. }
  185. /**
  186. * Enqueue scripts and styles.
  187. */
  188. function gazette_scripts() {
  189. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  190. wp_enqueue_style( 'gazette-lora', gazette_lora_font_url() );
  191. wp_enqueue_style( 'gazette-lato-inconsolata', gazette_lato_inconsolata_fonts_url() );
  192. wp_enqueue_style( 'gazette-style', get_stylesheet_uri() );
  193. // Block stylesheets
  194. wp_enqueue_style( 'gazette-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'gazette-style' ), '20181018' );
  195. wp_enqueue_script( 'gazette-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20150507', true );
  196. wp_enqueue_script( 'gazette-featured-content', get_template_directory_uri() . '/js/featured-content.js', array( 'jquery' ), '20150507', true );
  197. wp_enqueue_script( 'gazette-header', get_template_directory_uri() . '/js/header.js', array( 'jquery' ), '20150507', true );
  198. wp_enqueue_script( 'gazette-search', get_template_directory_uri() . '/js/search.js', array( 'jquery' ), '20150507', true );
  199. if ( ( is_single() && ( ( gazette_has_post_thumbnail() && gazette_jetpack_featured_image_display() ) && ( ! has_post_format() || has_post_format( 'aside' ) || has_post_format( 'image' ) || has_post_format( 'gallery' ) ) ) ) || ( is_page() && has_post_thumbnail() && gazette_jetpack_featured_image_display() ) ) {
  200. wp_enqueue_script( 'gazette-single-thumbnail', get_template_directory_uri() . '/js/single-thumbnail.js', array( 'jquery' ), '20150416', true );
  201. }
  202. if ( is_singular() ) {
  203. wp_enqueue_script( 'gazette-single', get_template_directory_uri() . '/js/single.js', array( 'jquery' ), '20150507', true );
  204. }
  205. if ( is_singular() && is_active_sidebar( 'sidebar-1' ) ) {
  206. wp_enqueue_script( 'gazette-sidebar', get_template_directory_uri() . '/js/sidebar.js', array(), '20150429', true );
  207. }
  208. if ( is_home() || is_archive() || is_search() ) {
  209. wp_enqueue_script( 'gazette-posts', get_template_directory_uri() . '/js/posts.js', array( 'jquery' ), '20150507', true );
  210. }
  211. wp_enqueue_script( 'gazette-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  212. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  213. wp_enqueue_script( 'comment-reply' );
  214. }
  215. }
  216. add_action( 'wp_enqueue_scripts', 'gazette_scripts' );
  217. /**
  218. * Enqueue editor styles for Gutenberg
  219. */
  220. function gazette_block_editor_styles() {
  221. // Block styles.
  222. wp_enqueue_style( 'gazette-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  223. // Custom fonts.
  224. wp_enqueue_style( 'gazette-lato-inconsolata', gazette_lato_inconsolata_fonts_url(), array(), null );
  225. // Genericons.
  226. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  227. }
  228. add_action( 'enqueue_block_editor_assets', 'gazette_block_editor_styles' );
  229. /**
  230. * Implement the Custom Header feature.
  231. */
  232. require get_template_directory() . '/inc/custom-header.php';
  233. /**
  234. * Custom template tags for this theme.
  235. */
  236. require get_template_directory() . '/inc/template-tags.php';
  237. /**
  238. * Custom functions that act independently of the theme templates.
  239. */
  240. require get_template_directory() . '/inc/extras.php';
  241. /**
  242. * Customizer additions.
  243. */
  244. require get_template_directory() . '/inc/customizer.php';
  245. /**
  246. * Load Jetpack compatibility file.
  247. */
  248. require get_template_directory() . '/inc/jetpack.php';