functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. /**
  3. * components functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Karuna
  8. */
  9. if ( ! function_exists( 'karuna_setup' ) ) :
  10. /**
  11. * Sets up theme defaults and registers support for various WordPress features.
  12. *
  13. * Note that this function is hooked into the aftercomponentsetup_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 karuna_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 'karuna' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'karuna', 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. // Add support for responsive embeds.
  35. add_theme_support( 'responsive-embeds' );
  36. /**
  37. * Gutenberg wide and full images support
  38. */
  39. add_theme_support( 'align-wide' );
  40. // Add custom colors to Gutenberg
  41. add_theme_support(
  42. 'editor-color-palette',
  43. array(
  44. array(
  45. 'name' => esc_html__( 'Black', 'karuna' ),
  46. 'slug' => 'black',
  47. 'color' => '#333333',
  48. ),
  49. array(
  50. 'name' => esc_html__( 'Medium Gray', 'karuna' ),
  51. 'slug' => 'medium-gray',
  52. 'color' => '#999999',
  53. ),
  54. array(
  55. 'name' => esc_html__( 'Light Gray', 'karuna' ),
  56. 'slug' => 'light-gray',
  57. 'color' => '#dddddd',
  58. ),
  59. array(
  60. 'name' => esc_html__( 'White', 'karuna' ),
  61. 'slug' => 'white',
  62. 'color' => '#ffffff',
  63. ),
  64. array(
  65. 'name' => esc_html__( 'Purple', 'karuna' ),
  66. 'slug' => 'purple',
  67. 'color' => '#6636cc',
  68. ),
  69. array(
  70. 'name' => esc_html__( 'Dark Purple', 'karuna' ),
  71. 'slug' => 'dark-purple',
  72. 'color' => '#471e9e',
  73. ),
  74. array(
  75. 'name' => esc_html__( 'Green', 'karuna' ),
  76. 'slug' => 'green',
  77. 'color' => '#85cc36',
  78. ),
  79. array(
  80. 'name' => esc_html__( 'Dark Green', 'karuna' ),
  81. 'slug' => 'dark-green',
  82. 'color' => '#609d1b',
  83. ),
  84. )
  85. );
  86. /*
  87. * Enable support for Post Thumbnails on posts and pages.
  88. *
  89. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  90. */
  91. add_theme_support( 'post-thumbnails' );
  92. add_image_size( 'karuna-featured-image', 685, 9999 );
  93. add_image_size( 'karuna-hero', 2000, 9999 );
  94. add_image_size( 'karuna-grid', 342, 228, true );
  95. add_image_size( 'karuna-thumbnail-avatar', 100, 100, true );
  96. // This theme uses wp_nav_menu() in one location.
  97. register_nav_menus(
  98. array(
  99. 'menu-1' => esc_html__( 'Header', 'karuna' ),
  100. )
  101. );
  102. /*
  103. * Switch default core markup for search form, comment form, and comments
  104. * to output valid HTML5.
  105. */
  106. add_theme_support(
  107. 'html5',
  108. array(
  109. 'search-form',
  110. 'comment-form',
  111. 'comment-list',
  112. 'gallery',
  113. 'caption',
  114. )
  115. );
  116. // Add theme support for custom logos
  117. add_theme_support(
  118. 'custom-logo',
  119. array(
  120. 'width' => 1000,
  121. 'height' => 200,
  122. 'flex-width' => true,
  123. 'flex-height' => true,
  124. )
  125. );
  126. // Set up the WordPress core custom background feature.
  127. add_theme_support(
  128. 'custom-background',
  129. apply_filters(
  130. 'karuna_custom_background_args',
  131. array(
  132. 'default-color' => 'ffffff',
  133. )
  134. )
  135. );
  136. }
  137. endif;
  138. add_action( 'after_setup_theme', 'karuna_setup' );
  139. /**
  140. * Return early if Custom Logos are not available.
  141. */
  142. function karuna_the_custom_logo() {
  143. if ( ! function_exists( 'the_custom_logo' ) ) {
  144. return;
  145. } else {
  146. the_custom_logo();
  147. }
  148. }
  149. /**
  150. * Set the content width in pixels, based on the theme's design and stylesheet.
  151. *
  152. * Priority 0 to make it available to lower priority callbacks.
  153. *
  154. * @global int $content_width
  155. */
  156. function karuna_content_width() {
  157. $GLOBALS['content_width'] = apply_filters( 'karuna_content_width', 685 );
  158. }
  159. add_action( 'after_setup_theme', 'karuna_content_width', 0 );
  160. /*
  161. * Adjust $content_width for full-width and front-page.php templates
  162. */
  163. if ( ! function_exists( 'karuna_adjusted_content_width' ) ) :
  164. function karuna_adjusted_content_width() {
  165. global $content_width;
  166. if ( is_page_template( 'templates/full-width-page.php' ) || is_page_template( 'front-page.php' ) || is_active_sidebar( 'sidebar-5' ) || is_active_sidebar( 'sidebar-4' ) ) {
  167. $content_width = 1040; //pixels
  168. }
  169. }
  170. add_action( 'template_redirect', 'karuna_adjusted_content_width' );
  171. endif; // if ! function_exists( 'karuna_adjusted_content_width' )
  172. /**
  173. * Register widget area.
  174. *
  175. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  176. */
  177. function karuna_widgets_init() {
  178. register_sidebar(
  179. array(
  180. 'name' => esc_html__( 'Sidebar', 'karuna' ),
  181. 'id' => 'sidebar-1',
  182. 'description' => '',
  183. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  184. 'after_widget' => '</section>',
  185. 'before_title' => '<h2 class="widget-title">',
  186. 'after_title' => '</h2>',
  187. )
  188. );
  189. register_sidebar(
  190. array(
  191. 'name' => esc_html__( 'Full-Width Header', 'karuna' ),
  192. 'id' => 'sidebar-4',
  193. 'description' => '',
  194. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  195. 'after_widget' => '</section>',
  196. 'before_title' => '<h2 class="widget-title">',
  197. 'after_title' => '</h2>',
  198. )
  199. );
  200. register_sidebar(
  201. array(
  202. 'name' => esc_html__( 'Full-Width Footer', 'karuna' ),
  203. 'id' => 'sidebar-5',
  204. 'description' => '',
  205. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  206. 'after_widget' => '</section>',
  207. 'before_title' => '<h2 class="widget-title">',
  208. 'after_title' => '</h2>',
  209. )
  210. );
  211. register_sidebar(
  212. array(
  213. 'name' => esc_html__( 'Footer 1', 'karuna' ),
  214. 'id' => 'sidebar-2',
  215. 'description' => '',
  216. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  217. 'after_widget' => '</section>',
  218. 'before_title' => '<h2 class="widget-title">',
  219. 'after_title' => '</h2>',
  220. )
  221. );
  222. register_sidebar(
  223. array(
  224. 'name' => esc_html__( 'Footer 2', 'karuna' ),
  225. 'id' => 'sidebar-3',
  226. 'description' => '',
  227. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  228. 'after_widget' => '</section>',
  229. 'before_title' => '<h2 class="widget-title">',
  230. 'after_title' => '</h2>',
  231. )
  232. );
  233. register_sidebar(
  234. array(
  235. 'name' => esc_html__( 'Footer 3', 'karuna' ),
  236. 'id' => 'sidebar-6',
  237. 'description' => '',
  238. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  239. 'after_widget' => '</section>',
  240. 'before_title' => '<h2 class="widget-title">',
  241. 'after_title' => '</h2>',
  242. )
  243. );
  244. register_sidebar(
  245. array(
  246. 'name' => esc_html__( 'Footer 4', 'karuna' ),
  247. 'id' => 'sidebar-7',
  248. 'description' => '',
  249. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  250. 'after_widget' => '</section>',
  251. 'before_title' => '<h2 class="widget-title">',
  252. 'after_title' => '</h2>',
  253. )
  254. );
  255. }
  256. add_action( 'widgets_init', 'karuna_widgets_init' );
  257. /**
  258. * Register Google Fonts
  259. */
  260. function karuna_fonts_url() {
  261. $fonts_url = '';
  262. /* Translators: If there are characters in your language that are not
  263. * supported by Karla, translate this to 'off'. Do not translate
  264. * into your own language.
  265. */
  266. $karla = esc_html_x( 'on', 'Karla font: on or off', 'karuna' );
  267. if ( 'off' !== $karla ) {
  268. $font_families = array();
  269. $font_families[] = 'Karla:400,400italic,700,700italic';
  270. /**
  271. * A filter to enable child themes to add/change/omit font families.
  272. *
  273. * @param array $font_families An array of font families to be imploded for the Google Font API
  274. */
  275. $font_families = apply_filters( 'included_google_font_families', $font_families );
  276. $query_args = array(
  277. 'family' => urlencode( implode( '|', $font_families ) ),
  278. 'subset' => urlencode( 'latin,latin-ext' ),
  279. );
  280. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  281. }
  282. return $fonts_url;
  283. }
  284. /**
  285. * Enqueue scripts and styles.
  286. */
  287. function karuna_scripts() {
  288. wp_enqueue_style( 'karuna-style', get_stylesheet_uri() );
  289. // Gutenberg styles
  290. wp_enqueue_style( 'karuna-blocks', get_template_directory_uri() . '/blocks.css' );
  291. wp_enqueue_style( 'karuna-fonts', karuna_fonts_url(), array(), null );
  292. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/fonts/genericons/genericons.css', array(), '3.4.1' );
  293. wp_enqueue_script( 'karuna-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  294. wp_enqueue_script( 'karuna-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  295. wp_enqueue_script( 'karuna-functions', get_template_directory_uri() . '/assets/js/functions.js', array( 'jquery' ), '20160531', true );
  296. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  297. wp_enqueue_script( 'comment-reply' );
  298. }
  299. }
  300. add_action( 'wp_enqueue_scripts', 'karuna_scripts' );
  301. /**
  302. * Gutenberg Editor Styles
  303. */
  304. function karuna_editor_styles() {
  305. wp_enqueue_style( 'karuna-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  306. wp_enqueue_style( 'karuna-fonts', karuna_fonts_url(), array(), null );
  307. }
  308. add_action( 'enqueue_block_editor_assets', 'karuna_editor_styles' );
  309. /**
  310. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  311. * @return string 'Continue reading' link prepended with an ellipsis.
  312. */
  313. if ( ! function_exists( 'karuna_excerpt_more' ) ) :
  314. function karuna_excerpt_more( $more ) {
  315. $link = sprintf(
  316. '<a href="%1$s" class="more-link">%2$s</a>',
  317. esc_url( get_permalink( get_the_ID() ) ),
  318. /* translators: %s: Name of current post */
  319. sprintf( esc_html__( 'Continue reading %s', 'karuna' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  320. );
  321. return ' &hellip; ' . $link;
  322. }
  323. add_filter( 'excerpt_more', 'karuna_excerpt_more' );
  324. endif;
  325. /**
  326. * Custom header support
  327. */
  328. require get_template_directory() . '/inc/custom-header.php';
  329. /**
  330. * Custom template tags for this theme.
  331. */
  332. require get_template_directory() . '/inc/template-tags.php';
  333. /**
  334. * Custom functions that act independently of the theme templates.
  335. */
  336. require get_template_directory() . '/inc/extras.php';
  337. /**
  338. * Customizer additions.
  339. */
  340. require get_template_directory() . '/inc/customizer.php';
  341. /**
  342. * Load Jetpack compatibility file.
  343. */
  344. require get_template_directory() . '/inc/jetpack.php';
  345. /**
  346. * Load WooCommerce compatibility file.
  347. */
  348. if ( class_exists( 'WooCommerce' ) ) {
  349. require get_template_directory() . '/inc/woocommerce.php';
  350. }