functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * Canard functions and definitions
  4. *
  5. * @package Canard
  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( 'canard_content_width' ) ) {
  14. function canard_content_width() {
  15. global $content_width;
  16. if ( is_page() ) {
  17. $content_width = 869;
  18. }
  19. }
  20. }
  21. add_action( 'template_redirect', 'canard_content_width' );
  22. if ( ! function_exists( 'canard_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 canard_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 Canard, use a find and replace
  35. * to change 'canard' to the name of your theme in all the template files
  36. */
  37. load_theme_textdomain( 'canard', 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( 'canard-post-thumbnail', 870, 773, true );
  54. add_image_size( 'canard-featured-content-thumbnail', 915, 500, true );
  55. add_image_size( 'canard-single-thumbnail', 1920, 768, true );
  56. // Add support for responsive embeds.
  57. add_theme_support( 'responsive-embeds' );
  58. // Add custom colors to Gutenberg
  59. add_theme_support(
  60. 'editor-color-palette',
  61. array(
  62. array(
  63. 'name' => esc_html__( 'Black', 'canard' ),
  64. 'slug' => 'black',
  65. 'color' => '#222222',
  66. ),
  67. array(
  68. 'name' => esc_html__( 'Dark Gray', 'canard' ),
  69. 'slug' => 'dark-gray',
  70. 'color' => '#555555',
  71. ),
  72. array(
  73. 'name' => esc_html__( 'Medium Gray', 'canard' ),
  74. 'slug' => 'medium-gray',
  75. 'color' => '#777777',
  76. ),
  77. array(
  78. 'name' => esc_html__( 'Light Gray', 'canard' ),
  79. 'slug' => 'light-gray',
  80. 'color' => '#dddddd',
  81. ),
  82. array(
  83. 'name' => esc_html__( 'White', 'canard' ),
  84. 'slug' => 'white',
  85. 'color' => '#ffffff',
  86. ),
  87. array(
  88. 'name' => esc_html__( 'Red', 'canard' ),
  89. 'slug' => 'red',
  90. 'color' => '#d11415',
  91. ),
  92. )
  93. );
  94. // This theme uses wp_nav_menu() in four locations.
  95. register_nav_menus(
  96. array(
  97. 'primary' => __( 'Primary Location', 'canard' ),
  98. 'secondary' => __( 'Secondary Location', 'canard' ),
  99. 'footer' => __( 'Footer Location', 'canard' ),
  100. 'social' => __( 'Social Location', 'canard' ),
  101. )
  102. );
  103. /*
  104. * Switch default core markup for search form, comment form, and comments
  105. * to output valid HTML5.
  106. */
  107. add_theme_support(
  108. 'html5',
  109. array(
  110. 'search-form',
  111. 'comment-form',
  112. 'comment-list',
  113. 'gallery',
  114. 'caption',
  115. )
  116. );
  117. /*
  118. * Enable support for Post Formats.
  119. * See http://codex.wordpress.org/Post_Formats
  120. */
  121. add_theme_support(
  122. 'post-formats',
  123. array(
  124. 'image',
  125. 'link',
  126. 'gallery',
  127. )
  128. );
  129. }
  130. endif; // canard_setup
  131. add_action( 'after_setup_theme', 'canard_setup' );
  132. /**
  133. * Register widget area.
  134. *
  135. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  136. */
  137. function canard_widgets_init() {
  138. register_sidebar(
  139. array(
  140. 'name' => __( 'Sidebar', 'canard' ),
  141. 'id' => 'sidebar-1',
  142. 'description' => '',
  143. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  144. 'after_widget' => '</aside>',
  145. 'before_title' => '<h2 class="widget-title">',
  146. 'after_title' => '</h2>',
  147. )
  148. );
  149. register_sidebar(
  150. array(
  151. 'name' => __( 'Footer', 'canard' ),
  152. 'id' => 'sidebar-2',
  153. 'description' => '',
  154. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  155. 'after_widget' => '</aside>',
  156. 'before_title' => '<h2 class="widget-title">',
  157. 'after_title' => '</h2>',
  158. )
  159. );
  160. }
  161. add_action( 'widgets_init', 'canard_widgets_init' );
  162. /**
  163. * Register Lato and Inconsolata fonts.
  164. *
  165. * @return string
  166. */
  167. function canard_lato_inconsolata_fonts_url() {
  168. $fonts_url = '';
  169. /* translators: If there are characters in your language that are not supported
  170. * by Lato, translate this to 'off'. Do not translate into your own language.
  171. */
  172. $lato = _x( 'on', 'Lato font: on or off', 'canard' );
  173. /* translators: If there are characters in your language that are not supported
  174. * by Inconsolata, translate this to 'off'. Do not translate into your own language.
  175. */
  176. $inconsolata = _x( 'on', 'Inconsolata font: on or off', 'canard' );
  177. if ( 'off' !== $lato || 'off' !== $inconsolata ) {
  178. $font_families = array();
  179. if ( 'off' !== $lato ) {
  180. $font_families[] = 'Lato:400,700,400italic,700italic';
  181. }
  182. if ( 'off' !== $inconsolata ) {
  183. $font_families[] = 'Inconsolata:400,700';
  184. }
  185. $query_args = array(
  186. 'family' => urlencode( implode( '|', $font_families ) ),
  187. 'subset' => urlencode( 'latin,latin-ext' ),
  188. );
  189. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  190. }
  191. return $fonts_url;
  192. }
  193. /**
  194. * Register PT Serif and Playfair Display fonts.
  195. *
  196. * @return string
  197. */
  198. function canard_pt_serif_playfair_display_font_url() {
  199. $fonts_url = '';
  200. /* translators: If there are characters in your language that are not supported
  201. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  202. */
  203. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'canard' );
  204. /* translators: If there are characters in your language that are not supported
  205. * by Playfair Display, translate this to 'off'. Do not translate into your own language.
  206. */
  207. $playfair_display = _x( 'on', 'Playfair Display font: on or off', 'canard' );
  208. if ( 'off' !== $pt_serif || 'off' !== $playfair_display ) {
  209. $font_families = array();
  210. if ( 'off' !== $pt_serif ) {
  211. $font_families[] = 'PT Serif:400,700,400italic,700italic';
  212. }
  213. if ( 'off' !== $playfair_display ) {
  214. $font_families[] = 'Playfair Display:400,700,400italic,700italic';
  215. }
  216. $query_args = array(
  217. 'family' => urlencode( implode( '|', $font_families ) ),
  218. 'subset' => urlencode( 'cyrillic,latin,latin-ext' ),
  219. );
  220. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  221. }
  222. return $fonts_url;
  223. }
  224. /**
  225. * Enqueue scripts and styles.
  226. */
  227. function canard_scripts() {
  228. // Gutenberg styles
  229. wp_enqueue_style( 'canard-blocks', get_template_directory_uri() . '/blocks.css' );
  230. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  231. wp_enqueue_style( 'canard-pt-serif-playfair-display', canard_pt_serif_playfair_display_font_url() );
  232. wp_enqueue_style( 'canard-lato-inconsolata', canard_lato_inconsolata_fonts_url() );
  233. wp_enqueue_style( 'canard-style', get_stylesheet_uri() );
  234. wp_enqueue_script( 'canard-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20150507', true );
  235. wp_enqueue_script( 'canard-featured-content', get_template_directory_uri() . '/js/featured-content.js', array( 'jquery' ), '20150507', true );
  236. wp_enqueue_script( 'canard-header', get_template_directory_uri() . '/js/header.js', array(), '20150908', true );
  237. wp_enqueue_script( 'canard-search', get_template_directory_uri() . '/js/search.js', array( 'jquery' ), '20150507', true );
  238. if ( ( is_single() && ( ( has_post_thumbnail() && canard_jetpack_featured_image_display() ) && ( ! has_post_format() || has_post_format( 'aside' ) || has_post_format( 'image' ) || has_post_format( 'gallery' ) ) ) ) || ( is_page() && has_post_thumbnail() && canard_jetpack_featured_image_display() ) ) {
  239. wp_enqueue_script( 'canard-single-thumbnail', get_template_directory_uri() . '/js/single-thumbnail.js', array( 'jquery' ), '20150416', true );
  240. }
  241. if ( is_singular() ) {
  242. wp_enqueue_script( 'canard-single', get_template_directory_uri() . '/js/single.js', array( 'jquery' ), '20150507', true );
  243. }
  244. if ( is_active_sidebar( 'sidebar-1' ) ) {
  245. wp_enqueue_script( 'canard-sidebar', get_template_directory_uri() . '/js/sidebar.js', array(), '20150429', true );
  246. }
  247. if ( is_home() || is_archive() || is_search() ) {
  248. wp_enqueue_script( 'canard-posts', get_template_directory_uri() . '/js/posts.js', array( 'jquery' ), '20150507', true );
  249. }
  250. wp_enqueue_script( 'canard-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  251. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  252. wp_enqueue_script( 'comment-reply' );
  253. }
  254. }
  255. add_action( 'wp_enqueue_scripts', 'canard_scripts' );
  256. /**
  257. * Gutenberg Editor Styles
  258. */
  259. function canard_editor_styles() {
  260. wp_enqueue_style( 'canard-block-style', get_template_directory_uri() . '/blocks.css' );
  261. wp_enqueue_style( 'canard-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  262. wp_enqueue_style( 'canard-pt-serif-playfair-display', canard_pt_serif_playfair_display_font_url() );
  263. wp_enqueue_style( 'canard-lato-inconsolata', canard_lato_inconsolata_fonts_url() );
  264. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  265. }
  266. add_action( 'enqueue_block_editor_assets', 'canard_editor_styles' );
  267. /**
  268. * Implement the Custom Header feature.
  269. */
  270. require get_template_directory() . '/inc/custom-header.php';
  271. /**
  272. * Custom template tags for this theme.
  273. */
  274. require get_template_directory() . '/inc/template-tags.php';
  275. /**
  276. * Custom functions that act independently of the theme templates.
  277. */
  278. require get_template_directory() . '/inc/extras.php';
  279. /**
  280. * Customizer additions.
  281. */
  282. require get_template_directory() . '/inc/customizer.php';
  283. /**
  284. * Load Jetpack compatibility file.
  285. */
  286. require get_template_directory() . '/inc/jetpack.php';