functions.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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(
  59. array(
  60. 'primary' => __( 'Primary Location', 'gazette' ),
  61. 'social' => __( 'Social Location', 'gazette' ),
  62. )
  63. );
  64. /*
  65. * Switch default core markup for search form, comment form, and comments
  66. * to output valid HTML5.
  67. */
  68. add_theme_support(
  69. 'html5',
  70. array(
  71. 'search-form',
  72. 'comment-form',
  73. 'comment-list',
  74. 'gallery',
  75. 'caption',
  76. )
  77. );
  78. /*
  79. * Enable support for Post Formats.
  80. * See http://codex.wordpress.org/Post_Formats
  81. */
  82. add_theme_support(
  83. 'post-formats',
  84. array(
  85. 'image',
  86. 'video',
  87. 'link',
  88. 'gallery',
  89. )
  90. );
  91. // Add support for responsive embeds.
  92. add_theme_support( 'responsive-embeds' );
  93. // Add support for custom color scheme.
  94. add_theme_support(
  95. 'editor-color-palette',
  96. array(
  97. array(
  98. 'name' => esc_html__( 'Blue', 'gazette' ),
  99. 'slug' => 'blue',
  100. 'color' => '#3863c1',
  101. ),
  102. array(
  103. 'name' => esc_html__( 'Dark Gray', 'gazette' ),
  104. 'slug' => 'dark-gray',
  105. 'color' => '#222',
  106. ),
  107. array(
  108. 'name' => esc_html__( 'Medium Gray', 'gazette' ),
  109. 'slug' => 'medium-gray',
  110. 'color' => '#777',
  111. ),
  112. array(
  113. 'name' => esc_html__( 'Light Gray', 'gazette' ),
  114. 'slug' => 'light-gray',
  115. 'color' => '#ddd',
  116. ),
  117. array(
  118. 'name' => esc_html__( 'White', 'gazette' ),
  119. 'slug' => 'white',
  120. 'color' => '#fff',
  121. ),
  122. )
  123. );
  124. }
  125. endif; // gazette_setup
  126. add_action( 'after_setup_theme', 'gazette_setup' );
  127. /**
  128. * Register widget area.
  129. *
  130. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  131. */
  132. function gazette_widgets_init() {
  133. register_sidebar(
  134. array(
  135. 'name' => __( 'Sidebar', 'gazette' ),
  136. 'id' => 'sidebar-1',
  137. 'description' => '',
  138. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  139. 'after_widget' => '</aside>',
  140. 'before_title' => '<h2 class="widget-title">',
  141. 'after_title' => '</h2>',
  142. )
  143. );
  144. register_sidebar(
  145. array(
  146. 'name' => __( 'Footer', 'gazette' ),
  147. 'id' => 'sidebar-2',
  148. 'description' => '',
  149. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  150. 'after_widget' => '</aside>',
  151. 'before_title' => '<h2 class="widget-title">',
  152. 'after_title' => '</h2>',
  153. )
  154. );
  155. }
  156. add_action( 'widgets_init', 'gazette_widgets_init' );
  157. /**
  158. * Register Lato and Inconsolata fonts.
  159. *
  160. * @return string
  161. */
  162. function gazette_lato_inconsolata_fonts_url() {
  163. $fonts_url = '';
  164. /* translators: If there are characters in your language that are not supported
  165. * by Lato, translate this to 'off'. Do not translate into your own language.
  166. */
  167. $lato = _x( 'on', 'Lato font: on or off', 'gazette' );
  168. /* translators: If there are characters in your language that are not supported
  169. * by Inconsolata, translate this to 'off'. Do not translate into your own language.
  170. */
  171. $inconsolata = _x( 'on', 'Inconsolata font: on or off', 'gazette' );
  172. if ( 'off' !== $lato || 'off' !== $inconsolata ) {
  173. $font_families = array();
  174. if ( 'off' !== $lato ) {
  175. $font_families[] = 'Lato:400,700,900,400italic,700italic,900italic';
  176. }
  177. if ( 'off' !== $inconsolata ) {
  178. $font_families[] = 'Inconsolata:400,700';
  179. }
  180. $query_args = array(
  181. 'family' => urlencode( implode( '|', $font_families ) ),
  182. 'subset' => urlencode( 'latin,latin-ext' ), // add extra subset
  183. );
  184. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  185. }
  186. return $fonts_url;
  187. }
  188. /**
  189. * Register Lora font.
  190. *
  191. * @return string
  192. */
  193. function gazette_lora_font_url() {
  194. $lora_font_url = '';
  195. /* translators: If there are characters in your language that are not supported
  196. * by Lora, translate this to 'off'. Do not translate into your own language.
  197. */
  198. if ( 'off' !== _x( 'on', 'Lora font: on or off', 'gazette' ) ) {
  199. $query_args = array(
  200. 'family' => urlencode( 'Lora:400,700,400italic,700italic' ),
  201. 'subset' => urlencode( 'latin,latin-ext' ),
  202. );
  203. $lora_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  204. }
  205. return $lora_font_url;
  206. }
  207. /**
  208. * Enqueue scripts and styles.
  209. */
  210. function gazette_scripts() {
  211. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  212. wp_enqueue_style( 'gazette-lora', gazette_lora_font_url() );
  213. wp_enqueue_style( 'gazette-lato-inconsolata', gazette_lato_inconsolata_fonts_url() );
  214. wp_enqueue_style( 'gazette-style', get_stylesheet_uri() );
  215. // Block stylesheets
  216. wp_enqueue_style( 'gazette-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'gazette-style' ), '20181018' );
  217. wp_enqueue_script( 'gazette-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20150507', true );
  218. wp_enqueue_script( 'gazette-featured-content', get_template_directory_uri() . '/js/featured-content.js', array( 'jquery' ), '20150507', true );
  219. wp_enqueue_script( 'gazette-header', get_template_directory_uri() . '/js/header.js', array( 'jquery' ), '20150507', true );
  220. wp_enqueue_script( 'gazette-search', get_template_directory_uri() . '/js/search.js', array( 'jquery' ), '20150507', true );
  221. 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() ) ) {
  222. wp_enqueue_script( 'gazette-single-thumbnail', get_template_directory_uri() . '/js/single-thumbnail.js', array( 'jquery' ), '20150416', true );
  223. }
  224. if ( is_singular() ) {
  225. wp_enqueue_script( 'gazette-single', get_template_directory_uri() . '/js/single.js', array( 'jquery' ), '20150507', true );
  226. }
  227. if ( is_singular() && is_active_sidebar( 'sidebar-1' ) ) {
  228. wp_enqueue_script( 'gazette-sidebar', get_template_directory_uri() . '/js/sidebar.js', array(), '20150429', true );
  229. }
  230. if ( is_home() || is_archive() || is_search() ) {
  231. wp_enqueue_script( 'gazette-posts', get_template_directory_uri() . '/js/posts.js', array( 'jquery' ), '20150507', true );
  232. }
  233. wp_enqueue_script( 'gazette-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  234. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  235. wp_enqueue_script( 'comment-reply' );
  236. }
  237. }
  238. add_action( 'wp_enqueue_scripts', 'gazette_scripts' );
  239. /**
  240. * Enqueue editor styles for Gutenberg
  241. */
  242. function gazette_block_editor_styles() {
  243. // Block styles.
  244. wp_enqueue_style( 'gazette-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  245. // Custom fonts.
  246. wp_enqueue_style( 'gazette-lato-inconsolata', gazette_lato_inconsolata_fonts_url(), array(), null );
  247. // Genericons.
  248. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  249. }
  250. add_action( 'enqueue_block_editor_assets', 'gazette_block_editor_styles' );
  251. /**
  252. * Implement the Custom Header feature.
  253. */
  254. require get_template_directory() . '/inc/custom-header.php';
  255. /**
  256. * Custom template tags for this theme.
  257. */
  258. require get_template_directory() . '/inc/template-tags.php';
  259. /**
  260. * Custom functions that act independently of the theme templates.
  261. */
  262. require get_template_directory() . '/inc/extras.php';
  263. /**
  264. * Customizer additions.
  265. */
  266. require get_template_directory() . '/inc/customizer.php';
  267. /**
  268. * Load Jetpack compatibility file.
  269. */
  270. require get_template_directory() . '/inc/jetpack.php';