functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. /**
  3. * Radcliffe 2 functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Radcliffe 2
  8. */
  9. if ( ! function_exists( 'radcliffe_2_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 radcliffe_2_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 _s, use a find and replace
  22. * to change 'radcliffe-2' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'radcliffe-2', 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. add_image_size( 'radcliffe-post-image', 2000, 1500 );
  41. // This theme uses wp_nav_menu() in one location.
  42. register_nav_menus( array(
  43. 'menu-1' => esc_html__( 'Header', 'radcliffe-2' ),
  44. ) );
  45. /*
  46. * Switch default core markup for search form, comment form, and comments
  47. * to output valid HTML5.
  48. */
  49. add_theme_support( 'html5', array(
  50. 'search-form',
  51. 'comment-form',
  52. 'comment-list',
  53. 'gallery',
  54. 'caption',
  55. ) );
  56. // Add theme support for Custom Logo.
  57. add_theme_support( 'custom-logo', array(
  58. 'width' => 1200,
  59. 'height' => 900,
  60. 'flex-width' => true,
  61. 'flex-height' => true,
  62. 'header-text' => array( 'site-title', 'site-description' ),
  63. ) );
  64. // Set up the WordPress core custom background feature.
  65. add_theme_support( 'custom-background', apply_filters( 'radcliffe_2_custom_background_args', array(
  66. 'default-color' => 'ffffff',
  67. 'default-image' => '',
  68. ) ) );
  69. // Add theme support for selective refresh for widgets.
  70. add_theme_support( 'customize-selective-refresh-widgets' );
  71. // Add support for responsive embeds.
  72. add_theme_support( 'responsive-embeds' );
  73. // Gutenberg: Add Custom Palette
  74. $stylepack = get_theme_mod( 'active_style_pack' );
  75. if ( 'vintage' === $stylepack ) {
  76. add_theme_support( 'editor-color-palette', array(
  77. array(
  78. 'name' => esc_html__( 'Vintage Off-White', 'radcliffe-2' ),
  79. 'slug' => 'vintage-off-white',
  80. 'color' => '#fff',
  81. ),
  82. array(
  83. 'name' => esc_html__( 'Vintage Light Brown', 'radcliffe-2' ),
  84. 'slug' => 'vintage-light-brown',
  85. 'color' => '#c7c4b4',
  86. ),
  87. array(
  88. 'name' => esc_html__( 'Vintage Light Gray', 'radcliffe-2' ),
  89. 'slug' => 'vintage-light-gray',
  90. 'color' => '#666',
  91. ),
  92. array(
  93. 'name' => esc_html__( 'Vintage Dark Gray', 'radcliffe-2' ),
  94. 'slug' => 'vintage-dark-gray',
  95. 'color' => '#222',
  96. ),
  97. array(
  98. 'name' => esc_html__( 'Vintage Blue', 'radcliffe-2' ),
  99. 'slug' => 'vintage-blue',
  100. 'color' => '#2b6e9d',
  101. )
  102. ) );
  103. } else if ( 'colorful' === $stylepack ) {
  104. add_theme_support( 'editor-color-palette', array(
  105. array(
  106. 'name' => esc_html__( 'Colorful White', 'radcliffe-2' ),
  107. 'slug' => 'colorful-white',
  108. 'color' => '#fff',
  109. ),
  110. array(
  111. 'name' => esc_html__( 'Colorful Light Gray', 'radcliffe-2' ),
  112. 'slug' => 'colorful-light-gray',
  113. 'color' => '#e5e5e5',
  114. ),
  115. array(
  116. 'name' => esc_html__( 'Colorful Dark Gray', 'radcliffe-2' ),
  117. 'slug' => 'colorful-dark-gray',
  118. 'color' => '#222222',
  119. ),
  120. array(
  121. 'name' => esc_html__( 'Colorful Blue', 'radcliffe-2' ),
  122. 'slug' => 'colorful-blue',
  123. 'color' => '#4ba3c3',
  124. ),
  125. array(
  126. 'name' => esc_html__( 'Colorful Green', 'radcliffe-2' ),
  127. 'slug' => 'colorful-green',
  128. 'color' => '#71db9d',
  129. ),
  130. array(
  131. 'name' => esc_html__( 'Colorful Orange', 'radcliffe-2' ),
  132. 'slug' => 'colorful-orange',
  133. 'color' => '#d97059',
  134. )
  135. ) );
  136. } else if ( 'modern' === $stylepack ) {
  137. add_theme_support( 'editor-color-palette', array(
  138. array(
  139. 'name' => esc_html__( 'Modern White', 'radcliffe-2' ),
  140. 'slug' => 'modern-white',
  141. 'color' => '#fff',
  142. ),
  143. array(
  144. 'name' => esc_html__( 'Modern Light Gray', 'radcliffe-2' ),
  145. 'slug' => 'modern-light-gray',
  146. 'color' => '#f1f1f1',
  147. ),
  148. array(
  149. 'name' => esc_html__( 'Modern Medium Gray', 'radcliffe-2' ),
  150. 'slug' => 'modern-medium-gray',
  151. 'color' => '#aaa',
  152. ),
  153. array(
  154. 'name' => esc_html__( 'Modern Dark Gray', 'radcliffe-2' ),
  155. 'slug' => 'modern-dark-gray',
  156. 'color' => '#222',
  157. )
  158. ) );
  159. } else {
  160. add_theme_support( 'editor-color-palette', array(
  161. array(
  162. 'name' => esc_html__( 'White', 'radcliffe-2' ),
  163. 'slug' => 'white',
  164. 'color' => '#fff',
  165. ),
  166. array(
  167. 'name' => esc_html__( 'Dark Gray', 'radcliffe-2' ),
  168. 'slug' => 'dark-gray',
  169. 'color' => '#222',
  170. ),
  171. array(
  172. 'name' => esc_html__( 'Light Gray', 'radcliffe-2' ),
  173. 'slug' => 'light-gray',
  174. 'color' => '#666666',
  175. ),
  176. array(
  177. 'name' => esc_html__( 'Red', 'radcliffe-2' ),
  178. 'slug' => 'red',
  179. 'color' => '#ca2017',
  180. )
  181. ) );
  182. }
  183. // Add support for wide alignment
  184. add_theme_support( 'align-wide' );
  185. }
  186. endif;
  187. add_action( 'after_setup_theme', 'radcliffe_2_setup' );
  188. /**
  189. * Set the content width in pixels, based on the theme's design and stylesheet.
  190. *
  191. * Priority 0 to make it available to lower priority callbacks.
  192. *
  193. * @global int $content_width
  194. */
  195. function radcliffe_2_content_width() {
  196. $GLOBALS['content_width'] = apply_filters( 'radcliffe_2_content_width', 740 );
  197. }
  198. add_action( 'after_setup_theme', 'radcliffe_2_content_width', 0 );
  199. /**
  200. * Register widget area.
  201. *
  202. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  203. */
  204. function radcliffe_2_widgets_init() {
  205. register_sidebar( array(
  206. 'name' => esc_html__( 'Footer 1', 'radcliffe-2' ),
  207. 'id' => 'sidebar-1',
  208. 'description' => '',
  209. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  210. 'after_widget' => '</section>',
  211. 'before_title' => '<h2 class="widget-title">',
  212. 'after_title' => '</h2>',
  213. ) );
  214. register_sidebar( array(
  215. 'name' => esc_html__( 'Footer 2', 'radcliffe-2' ),
  216. 'id' => 'sidebar-2',
  217. 'description' => '',
  218. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  219. 'after_widget' => '</section>',
  220. 'before_title' => '<h2 class="widget-title">',
  221. 'after_title' => '</h2>',
  222. ) );
  223. register_sidebar( array(
  224. 'name' => esc_html__( 'Footer 3', 'radcliffe-2' ),
  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. add_action( 'widgets_init', 'radcliffe_2_widgets_init' );
  234. /**
  235. * Enqueue scripts and styles.
  236. */
  237. function radcliffe_2_scripts() {
  238. wp_enqueue_style( 'radcliffe-2-style', get_stylesheet_uri() );
  239. wp_enqueue_style( 'radcliffe-2-block-styles', get_template_directory_uri() . '/assets/css/blocks.css' );
  240. $stylepack = get_theme_mod( 'active_style_pack' );
  241. if ( 'vintage' === $stylepack ) {
  242. wp_enqueue_style( 'radcliffe-2-block-vintage-styles', get_template_directory_uri() . '/assets/css/blocks-vintage.css' );
  243. }
  244. wp_enqueue_script( 'radcliffe-2-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  245. wp_localize_script( 'radcliffe-2-navigation', 'screenReaderText', array(
  246. 'expand' => esc_html__( 'Expand child menu', 'radcliffe-2' ),
  247. 'collapse' => esc_html__( 'Collapse child menu', 'radcliffe-2' ),
  248. 'icon_expand' => radcliffe_2_get_svg( array( 'icon' => 'expand' ) ),
  249. 'icon_zoom' => radcliffe_2_get_svg( array( 'icon' => 'zoom' ) ),
  250. ) );
  251. wp_enqueue_script( 'radcliffe-2-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  252. wp_enqueue_script( 'radcliffe-2', get_template_directory_uri() . '/assets/js/radcliffe-2.js', array( 'jquery' ), '20170629', 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', 'radcliffe_2_scripts' );
  258. /**
  259. * Enqueue editor styles for Gutenberg
  260. */
  261. function radcliffe_2_editor_styles() {
  262. wp_enqueue_style( 'radcliffe-2-editor-style', get_template_directory_uri() . '/assets/css/editor-style.css' );
  263. $stylepack = get_theme_mod( 'active_style_pack' );
  264. if ( 'colorful' === $stylepack ) {
  265. wp_enqueue_style( 'radcliffe-2-editor-style-colorful', get_template_directory_uri() . '/assets/css/editor-style-colorful.css' );
  266. } else if ( 'modern' === $stylepack ) {
  267. wp_enqueue_style( 'radcliffe-2-editor-style-modern', get_template_directory_uri() . '/assets/css/editor-style-modern.css' );
  268. } else if ( 'vintage' === $stylepack ) {
  269. wp_enqueue_style( 'radcliffe-2-editor-style-vintage', get_template_directory_uri() . '/assets/css/editor-style-vintage.css' );
  270. }
  271. }
  272. add_action( 'enqueue_block_editor_assets', 'radcliffe_2_editor_styles' );
  273. /**
  274. * Enqueue stylesheet inside the Customizer.
  275. */
  276. function radcliffe_2_custom_customize_enqueue() {
  277. wp_enqueue_style( 'customizer-css', get_stylesheet_directory_uri() . '/assets/css/customizer.css' );
  278. }
  279. add_action( 'customize_controls_enqueue_scripts', 'radcliffe_2_custom_customize_enqueue' );
  280. /**
  281. * Add a pingback url auto-discovery header for singularly identifiable articles.
  282. */
  283. function radcliffe_2_pingback_header() {
  284. if ( is_singular() && pings_open() ) {
  285. echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
  286. }
  287. }
  288. add_action( 'wp_head', 'radcliffe_2_pingback_header' );
  289. /**
  290. * Custom template tags for this theme.
  291. */
  292. require get_template_directory() . '/inc/template-tags.php';
  293. /**
  294. * Additional features to allow styling of the templates.
  295. */
  296. require get_template_directory() . '/inc/template-functions.php';
  297. /**
  298. * Style packs.
  299. */
  300. require get_template_directory() . '/inc/style-packs-core.php';
  301. require get_template_directory() . '/inc/style-packs.php';
  302. /**
  303. * Customizer additions.
  304. */
  305. require get_template_directory() . '/inc/customizer.php';
  306. /**
  307. * SVG icons functions and filters.
  308. */
  309. require get_parent_theme_file_path( '/inc/icon-functions.php' );
  310. /**
  311. * Load Jetpack compatibility file.
  312. */
  313. require get_template_directory() . '/inc/jetpack.php';
  314. /**
  315. * Load Hero Area code.
  316. */
  317. require get_template_directory() . '/hero-area/hero-area-functions.php';
  318. /**
  319. * Load Contact Info code.
  320. */
  321. require get_template_directory() . '/contact-info/contact-info-functions.php';
  322. /**
  323. * Load WooCommerce compatibility file.
  324. */
  325. if ( class_exists( 'WooCommerce' ) ) {
  326. require get_template_directory() . '/inc/woocommerce.php';
  327. }