functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?php
  2. /**
  3. * Ixion functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Ixion
  8. */
  9. if ( ! function_exists( 'ixion_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 ixion_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 'ixion' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'ixion', get_template_directory() . '/languages' );
  25. // Add default posts and comments RSS feed links to head.
  26. add_theme_support( 'automatic-feed-links' );
  27. // Add support for responsive embeds.
  28. add_theme_support( 'responsive-embeds' );
  29. /**
  30. * Gutenberg wide and full images support
  31. */
  32. add_theme_support( 'align-wide' );
  33. // Add custom colors to Gutenberg
  34. add_theme_support(
  35. 'editor-color-palette',
  36. array(
  37. array(
  38. 'name' => esc_html__( 'Black', 'ixion' ),
  39. 'slug' => 'black',
  40. 'color' => '#192930',
  41. ),
  42. array(
  43. 'name' => esc_html__( 'Dark Gray', 'ixion' ),
  44. 'slug' => 'dark-gray',
  45. 'color' => '#474f53',
  46. ),
  47. array(
  48. 'name' => esc_html__( 'Medium Gray', 'ixion' ),
  49. 'slug' => 'medium-gray',
  50. 'color' => '#a5a29d',
  51. ),
  52. array(
  53. 'name' => esc_html__( 'Light Gray', 'ixion' ),
  54. 'slug' => 'light-gray',
  55. 'color' => '#eeece8',
  56. ),
  57. array(
  58. 'name' => esc_html__( 'White', 'ixion' ),
  59. 'slug' => 'white',
  60. 'color' => '#ffffff',
  61. ),
  62. array(
  63. 'name' => esc_html__( 'Yellow', 'ixion' ),
  64. 'slug' => 'yellow',
  65. 'color' => '#d7b221',
  66. ),
  67. array(
  68. 'name' => esc_html__( 'Dark Yellow', 'ixion' ),
  69. 'slug' => 'dark-yellow',
  70. 'color' => '#9c8012',
  71. ),
  72. )
  73. );
  74. /*
  75. * Let WordPress manage the document title.
  76. * By adding theme support, we declare that this theme does not use a
  77. * hard-coded <title> tag in the document head, and expect WordPress to
  78. * provide it for us.
  79. */
  80. add_theme_support( 'title-tag' );
  81. /*
  82. * Enable support for Post Thumbnails on posts and pages.
  83. *
  84. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  85. */
  86. add_theme_support( 'post-thumbnails' );
  87. add_image_size( 'ixion-featured-content', 680, 382, true );
  88. add_image_size( 'ixion-featured-image', 1080, 9999 );
  89. add_image_size( 'ixion-avatar', 75, 75, true );
  90. // This theme uses wp_nav_menu() in three locations.
  91. register_nav_menus(
  92. array(
  93. 'menu-1' => esc_html__( 'Header', 'ixion' ),
  94. )
  95. );
  96. /**
  97. * Add support for core custom logo.
  98. */
  99. add_theme_support(
  100. 'custom-logo',
  101. array(
  102. 'height' => 100,
  103. 'width' => 500,
  104. 'flex-width' => true,
  105. 'flex-height' => true,
  106. )
  107. );
  108. /*
  109. * Switch default core markup for search form, comment form, and comments
  110. * to output valid HTML5.
  111. */
  112. add_theme_support(
  113. 'html5',
  114. array(
  115. 'search-form',
  116. 'comment-form',
  117. 'comment-list',
  118. 'gallery',
  119. 'caption',
  120. )
  121. );
  122. // Set up the WordPress core custom background feature.
  123. add_theme_support(
  124. 'custom-background',
  125. apply_filters(
  126. 'ixion_custom_background_args',
  127. array(
  128. 'default-color' => 'ffffff',
  129. )
  130. )
  131. );
  132. }
  133. endif;
  134. add_action( 'after_setup_theme', 'ixion_setup' );
  135. /**
  136. * Set the content width in pixels, based on the theme's design and stylesheet.
  137. *
  138. * Priority 0 to make it available to lower priority callbacks.
  139. *
  140. * @global int $content_width
  141. */
  142. function ixion_content_width() {
  143. $GLOBALS['content_width'] = apply_filters( 'ixion_content_width', 712 );
  144. }
  145. add_action( 'after_setup_theme', 'ixion_content_width', 0 );
  146. /**
  147. * Set larger content width in some situations.
  148. */
  149. function ixion_adjust_content_width() {
  150. /* Allow for full-width gallery display in the footer */
  151. if ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) || is_active_sidebar( 'sidebar-5' ) ) {
  152. $GLOBALS['content_width'] = 1080;
  153. }
  154. }
  155. add_action( 'template_redirect', 'ixion_adjust_content_width' );
  156. /**
  157. * Return early if Custom Logos are not available.
  158. *
  159. * @todo Remove after WP 4.7
  160. */
  161. function ixion_the_custom_logo() {
  162. if ( ! function_exists( 'the_custom_logo' ) ) {
  163. return;
  164. } else {
  165. the_custom_logo();
  166. }
  167. }
  168. /**
  169. * Register widget areas.
  170. *
  171. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  172. */
  173. function ixion_widgets_init() {
  174. register_sidebar(
  175. array(
  176. 'name' => esc_html__( 'Sidebar', 'ixion' ),
  177. 'id' => 'sidebar-1',
  178. 'description' => '',
  179. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  180. 'after_widget' => '</section>',
  181. 'before_title' => '<h2 class="widget-title">',
  182. 'after_title' => '</h2>',
  183. )
  184. );
  185. register_sidebar(
  186. array(
  187. 'name' => esc_html__( 'Footer 1', 'ixion' ),
  188. 'id' => 'sidebar-2',
  189. 'description' => '',
  190. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  191. 'after_widget' => '</section>',
  192. 'before_title' => '<h2 class="widget-title">',
  193. 'after_title' => '</h2>',
  194. )
  195. );
  196. register_sidebar(
  197. array(
  198. 'name' => esc_html__( 'Footer 2', 'ixion' ),
  199. 'id' => 'sidebar-3',
  200. 'description' => '',
  201. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  202. 'after_widget' => '</section>',
  203. 'before_title' => '<h2 class="widget-title">',
  204. 'after_title' => '</h2>',
  205. )
  206. );
  207. register_sidebar(
  208. array(
  209. 'name' => esc_html__( 'Footer 3', 'ixion' ),
  210. 'id' => 'sidebar-4',
  211. 'description' => '',
  212. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  213. 'after_widget' => '</section>',
  214. 'before_title' => '<h2 class="widget-title">',
  215. 'after_title' => '</h2>',
  216. )
  217. );
  218. register_sidebar(
  219. array(
  220. 'name' => esc_html__( 'Footer 4', 'ixion' ),
  221. 'id' => 'sidebar-5',
  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. }
  230. add_action( 'widgets_init', 'ixion_widgets_init' );
  231. /**
  232. * Register Google Fonts
  233. */
  234. function ixion_fonts_url_archivo() {
  235. $fonts_url = '';
  236. /* Translators: If there are characters in your language that are not
  237. * supported by Archivo Narrow, translate this to 'off'. Do not translate
  238. * into your own language.
  239. */
  240. $archivo = esc_html_x( 'on', 'Archivo Narrow font: on or off', 'ixion' );
  241. if ( 'off' !== $archivo ) {
  242. $font_families = array();
  243. $font_families[] = 'Archivo Narrow:400,400i,700,700i';
  244. $query_args = array(
  245. 'family' => urlencode( implode( '|', $font_families ) ),
  246. 'subset' => urlencode( 'latin,latin-ext' ),
  247. );
  248. $fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
  249. }
  250. return $fonts_url;
  251. }
  252. /**
  253. * Register local fonts
  254. */
  255. function ixion_fonts_url_cooper() {
  256. $fonts_url = '';
  257. /* Translators: If there are characters in your language that are not
  258. * supported by Cooper Hewitt, translate this to 'off'. Do not translate
  259. * into your own language.
  260. */
  261. $cooper = esc_html_x( 'on', 'Cooper Hewitt font: on or off', 'ixion' );
  262. if ( 'off' !== $cooper ) {
  263. $fonts_url = get_template_directory_uri() . '/assets/fonts/cooperhewitt.css';
  264. }
  265. return $fonts_url;
  266. }
  267. /**
  268. * Enqueue scripts and styles.
  269. */
  270. function ixion_scripts() {
  271. wp_enqueue_style( 'ixion-style', get_stylesheet_uri() );
  272. // Gutenberg styles
  273. wp_enqueue_style( 'ixion-blocks', get_template_directory_uri() . '/blocks.css' );
  274. wp_enqueue_style( 'ixion-fonts-archivo', ixion_fonts_url_archivo(), array(), null );
  275. wp_enqueue_style( 'ixion-fonts-cooper', ixion_fonts_url_cooper(), array(), null );
  276. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/fonts/genericons/genericons/genericons.css' );
  277. wp_enqueue_script( 'ixion-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  278. wp_enqueue_script( 'ixion-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  279. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  280. wp_enqueue_script( 'comment-reply' );
  281. }
  282. if ( is_post_type_archive( 'jetpack-testimonial' ) ) {
  283. wp_enqueue_script( 'masonry' );
  284. wp_enqueue_script( 'ixion-testimonials', get_template_directory_uri() . '/assets/js/testimonials.js', array( 'jquery', 'masonry' ), '24102016', true );
  285. }
  286. }
  287. add_action( 'wp_enqueue_scripts', 'ixion_scripts' );
  288. /**
  289. * Gutenberg Editor Styles
  290. */
  291. function ixion_editor_styles() {
  292. wp_enqueue_style( 'ixion-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  293. wp_enqueue_style( 'ixion-fonts-archivo', ixion_fonts_url_archivo(), array(), null );
  294. wp_enqueue_style( 'ixion-fonts-cooper', ixion_fonts_url_cooper(), array(), null );
  295. }
  296. add_action( 'enqueue_block_editor_assets', 'ixion_editor_styles' );
  297. /**
  298. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  299. * @return string 'Continue reading' link prepended with an ellipsis.
  300. */
  301. if ( ! function_exists( 'ixion_excerpt_more' ) ) :
  302. function ixion_excerpt_more( $more ) {
  303. $link = sprintf(
  304. '<a href="%1$s" class="more-link">%2$s</a>',
  305. esc_url( get_permalink( get_the_ID() ) ),
  306. /* translators: %s: Name of current post */
  307. sprintf( esc_html__( 'Continue reading %s', 'ixion' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  308. );
  309. return ' &hellip; ' . $link;
  310. }
  311. add_filter( 'excerpt_more', 'ixion_excerpt_more' );
  312. endif;
  313. /**
  314. * Custom header.
  315. */
  316. require get_template_directory() . '/inc/custom-header.php';
  317. /**
  318. * Custom template tags for this theme.
  319. */
  320. require get_template_directory() . '/inc/template-tags.php';
  321. /**
  322. * Custom functions that act independently of the theme templates.
  323. */
  324. require get_template_directory() . '/inc/extras.php';
  325. /**
  326. * Customizer additions.
  327. */
  328. require get_template_directory() . '/inc/customizer.php';
  329. /**
  330. * Load Jetpack compatibility file.
  331. */
  332. require get_template_directory() . '/inc/jetpack.php';