functions.php 9.9 KB

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