functions.php 11 KB

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