functions.php 10 KB

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