functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /**
  3. * Dara functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Dara
  8. */
  9. if ( ! function_exists( 'dara_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 dara_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 components, use a find and replace
  22. * to change 'dara' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'dara', 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. // Post thumbnails
  41. add_image_size( 'dara-featured-image', 880, 312, true );
  42. // Hero Image on the front page slider
  43. add_image_size( 'dara-hero-thumbnail', 1180, 600, true );
  44. // Full width and grid page template
  45. add_image_size( 'dara-page-thumbnail', 1180, 435, true );
  46. // Grid child page thumbnail
  47. add_image_size( 'dara-grid-thumbnail', 360, 242, true );
  48. // Testimonial thumbnail
  49. add_image_size( 'dara-testimonial-thumbnail', 180, 180, true );
  50. // Add support for responsive embeds.
  51. add_theme_support( 'responsive-embeds' );
  52. // Add custom colors to Gutenberg
  53. add_theme_support(
  54. 'editor-color-palette',
  55. array(
  56. array(
  57. 'name' => esc_html__( 'Black', 'dara' ),
  58. 'slug' => 'black',
  59. 'color' => '#404040',
  60. ),
  61. array(
  62. 'name' => esc_html__( 'Dark Gray', 'dara' ),
  63. 'slug' => 'dark-gray',
  64. 'color' => '#444340',
  65. ),
  66. array(
  67. 'name' => esc_html__( 'Medium Gray', 'dara' ),
  68. 'slug' => 'medium-gray',
  69. 'color' => '#a8a6a1',
  70. ),
  71. array(
  72. 'name' => esc_html__( 'Light Gray', 'dara' ),
  73. 'slug' => 'light-gray',
  74. 'color' => '#e6e6e6',
  75. ),
  76. array(
  77. 'name' => esc_html__( 'White', 'dara' ),
  78. 'slug' => 'white',
  79. 'color' => '#ffffff',
  80. ),
  81. array(
  82. 'name' => esc_html__( 'Blue', 'dara' ),
  83. 'slug' => 'blue',
  84. 'color' => '#15b6b8',
  85. ),
  86. array(
  87. 'name' => esc_html__( 'Dark Blue', 'dara' ),
  88. 'slug' => 'dark-blue',
  89. 'color' => '#0c8384',
  90. ),
  91. )
  92. );
  93. // This theme uses wp_nav_menu() in one location.
  94. register_nav_menus(
  95. array(
  96. 'menu-1' => esc_html__( 'Header', 'dara' ),
  97. )
  98. );
  99. /*
  100. * Switch default core markup for search form, comment form, and comments
  101. * to output valid HTML5.
  102. */
  103. add_theme_support(
  104. 'html5',
  105. array(
  106. 'search-form',
  107. 'comment-form',
  108. 'comment-list',
  109. 'gallery',
  110. 'caption',
  111. )
  112. );
  113. // Add theme support for selective refresh for widgets.
  114. add_theme_support( 'customize-selective-refresh-widgets' );
  115. // Set up the WordPress core custom background feature.
  116. add_theme_support(
  117. 'custom-background',
  118. apply_filters(
  119. 'dara_custom_background_args',
  120. array(
  121. 'default-color' => '444340',
  122. )
  123. )
  124. );
  125. // Add theme support for custom logos
  126. add_theme_support(
  127. 'custom-logo',
  128. array(
  129. 'width' => 1200,
  130. 'height' => 300,
  131. 'flex-width' => true,
  132. 'flex-height' => true,
  133. )
  134. );
  135. // Add theme support for excerpts on pages
  136. add_post_type_support( 'page', 'excerpt' );
  137. }
  138. endif;
  139. add_action( 'after_setup_theme', 'dara_setup' );
  140. /**
  141. * Set the content width in pixels, based on the theme's design and stylesheet.
  142. *
  143. * Priority 0 to make it available to lower priority callbacks.
  144. *
  145. * @global int $content_width
  146. */
  147. function dara_content_width() {
  148. $GLOBALS['content_width'] = apply_filters( 'dara_content_width', 825 );
  149. }
  150. add_action( 'after_setup_theme', 'dara_content_width', 0 );
  151. /**
  152. * Set larger content width in some situations.
  153. */
  154. function dara_adjust_content_width() {
  155. /* Set the content width for the front-page or testimonials templates */
  156. if ( is_post_type_archive( 'jetpack-testimonial' ) || ( is_front_page() ) ) {
  157. $GLOBALS['content_width'] = 1180;
  158. }
  159. /* Allow for full-width gallery display in the footer */
  160. if ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) ) {
  161. $GLOBALS['content_width'] = 1086;
  162. }
  163. }
  164. add_action( 'template_redirect', 'dara_adjust_content_width' );
  165. /**
  166. * Return early if Custom Logos are not available.
  167. *
  168. * @todo Remove after WP 4.7
  169. */
  170. function dara_the_custom_logo() {
  171. if ( ! function_exists( 'the_custom_logo' ) ) {
  172. return;
  173. } else {
  174. the_custom_logo();
  175. }
  176. }
  177. /**
  178. * Returns the Google font stylesheet URL, if available.
  179. */
  180. function dara_fonts_url() {
  181. $fonts_url = '';
  182. /* translators: If there are characters in your language that are not supported
  183. * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
  184. */
  185. $source_sans_pro = esc_html_x( 'on', 'Source Sans Pro font: on or off', 'dara' );
  186. /* translators: If there are characters in your language that are not supported
  187. * by Yrsa, translate this to 'off'. Do not translate into your own language.
  188. */
  189. $yrsa = esc_html_x( 'on', 'Yrsa font: on or off', 'dara' );
  190. if ( 'off' !== $source_sans_pro || 'off' !== $merriweather || 'off' !== $Yrsa ) {
  191. $font_families = array();
  192. if ( 'off' !== $source_sans_pro ) {
  193. $font_families[] = 'Source Sans Pro:300,300italic,400,400italic,600';
  194. }
  195. if ( 'off' !== $yrsa ) {
  196. $font_families[] = 'Yrsa:300,400,700';
  197. }
  198. /**
  199. * A filter to enable child themes to add/change/omit font families.
  200. *
  201. * @param array $font_families An array of font families to be imploded for the Google Font API
  202. */
  203. $font_families = apply_filters( 'included_google_font_families', $font_families );
  204. $query_args = array(
  205. 'family' => urlencode( implode( '|', $font_families ) ),
  206. 'subset' => urlencode( 'latin,latin-ext' ),
  207. );
  208. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  209. }
  210. return $fonts_url;
  211. }
  212. /**
  213. * Register widget area.
  214. *
  215. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  216. */
  217. function dara_widgets_init() {
  218. register_sidebar(
  219. array(
  220. 'name' => esc_html__( 'Sidebar', 'dara' ),
  221. 'id' => 'sidebar-1',
  222. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  223. 'after_widget' => '</aside>',
  224. 'before_title' => '<h3 class="widget-title">',
  225. 'after_title' => '</h3>',
  226. )
  227. );
  228. register_sidebar(
  229. array(
  230. 'name' => esc_html__( 'Footer 1', 'dara' ),
  231. 'id' => 'sidebar-2',
  232. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  233. 'after_widget' => '</aside>',
  234. 'before_title' => '<h3 class="widget-title">',
  235. 'after_title' => '</h3>',
  236. )
  237. );
  238. register_sidebar(
  239. array(
  240. 'name' => esc_html__( 'Footer 2', 'dara' ),
  241. 'id' => 'sidebar-3',
  242. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  243. 'after_widget' => '</aside>',
  244. 'before_title' => '<h3 class="widget-title">',
  245. 'after_title' => '</h3>',
  246. )
  247. );
  248. register_sidebar(
  249. array(
  250. 'name' => esc_html__( 'Footer 3', 'dara' ),
  251. 'id' => 'sidebar-4',
  252. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  253. 'after_widget' => '</aside>',
  254. 'before_title' => '<h3 class="widget-title">',
  255. 'after_title' => '</h3>',
  256. )
  257. );
  258. }
  259. add_action( 'widgets_init', 'dara_widgets_init' );
  260. /**
  261. * Enqueue scripts and styles.
  262. */
  263. function dara_scripts() {
  264. wp_enqueue_style( 'dara-style', get_stylesheet_uri() );
  265. // Gutenberg styles
  266. wp_enqueue_style( 'dara-blocks', get_template_directory_uri() . '/blocks.css' );
  267. // Add Yrsa, Source Sans Pro and Merriweather fonts.
  268. wp_enqueue_style( 'dara-fonts', dara_fonts_url(), array(), null );
  269. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/genericons/genericons.css', array(), '3.4.1' );
  270. wp_enqueue_script( 'dara-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  271. if ( dara_has_featured_posts( 1 ) && ( is_home() || is_front_page() ) ) {
  272. wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/assets/js/jquery.flexslider.js', array( 'jquery' ), '20161220', true );
  273. wp_enqueue_script( 'dara-slider', get_template_directory_uri() . '/assets/js/slider.js', array( 'flexslider', 'imagesloaded' ), '20161220', true );
  274. }
  275. // If there's an active Video widget, and it's (hopefully) in the footer widget area
  276. if ( is_active_widget( '', '', 'media_video' ) && ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) ) ) {
  277. wp_enqueue_script( 'dara-video', get_template_directory_uri() . '/assets/js/video-widget.js', array( 'jquery' ), '20170608', true );
  278. }
  279. wp_enqueue_script( 'dara-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  280. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  281. wp_enqueue_script( 'comment-reply' );
  282. }
  283. }
  284. add_action( 'wp_enqueue_scripts', 'dara_scripts' );
  285. /**
  286. * Gutenberg Editor Styles
  287. */
  288. function dara_editor_styles() {
  289. wp_enqueue_style( 'dara-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  290. wp_enqueue_style( 'dara-fonts', dara_fonts_url() );
  291. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  292. }
  293. add_action( 'enqueue_block_editor_assets', 'dara_editor_styles' );
  294. if ( ! function_exists( 'dara_continue_reading_link' ) ) :
  295. /**
  296. * Returns an ellipsis and "Continue reading" plus off-screen title link for excerpts
  297. */
  298. function dara_continue_reading_link() {
  299. return '&hellip; <a href="' . esc_url( get_permalink() ) . '" class="more-link">' . sprintf( __( 'Continue reading <span class="screen-reader-text">%1$s</span>', 'dara' ), esc_attr( strip_tags( get_the_title() ) ) ) . '</a>';
  300. }
  301. endif; // dara_continue_reading_link
  302. /**
  303. * Replaces "[...]" (appended to automatically generated excerpts) with dara_continue_reading_link().
  304. *
  305. * To override this in a child theme, remove the filter and add your own
  306. * function tied to the excerpt_more filter hook.
  307. */
  308. function dara_auto_excerpt_more() {
  309. if ( is_admin() ) {
  310. return;
  311. }
  312. return dara_continue_reading_link();
  313. }
  314. add_filter( 'excerpt_more', 'dara_auto_excerpt_more' );
  315. /**
  316. * Custom Header support.
  317. */
  318. require get_template_directory() . '/inc/custom-header.php';
  319. /**
  320. * Custom template tags for this theme.
  321. */
  322. require get_template_directory() . '/inc/template-tags.php';
  323. /**
  324. * Custom functions that act independently of the theme templates.
  325. */
  326. require get_template_directory() . '/inc/extras.php';
  327. /**
  328. * Customizer additions.
  329. */
  330. require get_template_directory() . '/inc/customizer.php';
  331. /**
  332. * Load Jetpack compatibility file.
  333. */
  334. require get_template_directory() . '/inc/jetpack.php';
  335. /**
  336. * Load WooCommerce compatibility file.
  337. */
  338. if ( class_exists( 'WooCommerce' ) ) {
  339. require get_template_directory() . '/inc/woocommerce.php';
  340. }