functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. /**
  3. * Apostrophe functions and definitions
  4. *
  5. * @package Apostrophe 2
  6. */
  7. /**
  8. * Set the content width in pixels, based on the theme's design and stylesheet.
  9. *
  10. * Priority 0 to make it available to lower priority callbacks.
  11. *
  12. * @global int $content_width
  13. */
  14. function apostrophe_2_content_width() {
  15. $GLOBALS['content_width'] = apply_filters( 'apostrophe_2_content_width', 723 );
  16. }
  17. add_action( 'after_setup_theme', 'apostrophe_2_content_width', 0 );
  18. /**
  19. * Sets up theme defaults and registers support for various WordPress features.
  20. *
  21. * Note that this function is hooked into the after_setup_theme hook, which
  22. * runs before the init hook. The init hook is too late for some features, such
  23. * as indicating support for post thumbnails.
  24. */
  25. if ( ! function_exists( 'apostrophe_2_setup' ) ) :
  26. function apostrophe_2_setup() {
  27. /*
  28. * Make theme available for translation.
  29. * Translations can be filed in the /languages/ directory.
  30. */
  31. load_theme_textdomain( 'apostrophe-2', get_template_directory() . '/languages' );
  32. // Add default posts and comments RSS feed links to head.
  33. add_theme_support( 'automatic-feed-links' );
  34. // Add wide styles support for Gutenberg
  35. add_theme_support( 'align-wide' );
  36. // Add support for responsive embeds.
  37. add_theme_support( 'responsive-embeds' );
  38. // Add custom colors to Gutenberg
  39. add_theme_support(
  40. 'editor-color-palette',
  41. array(
  42. array(
  43. 'name' => esc_html__( 'Black', 'apostrophe-2' ),
  44. 'slug' => 'black',
  45. 'color' => '#404040',
  46. ),
  47. array(
  48. 'name' => esc_html__( 'Dark Gray', 'apostrophe-2' ),
  49. 'slug' => 'dark-gray',
  50. 'color' => '#686868',
  51. ),
  52. array(
  53. 'name' => esc_html__( 'Medium Gray', 'apostrophe-2' ),
  54. 'slug' => 'medium-gray',
  55. 'color' => '#999999',
  56. ),
  57. array(
  58. 'name' => esc_html__( 'Light Gray', 'apostrophe-2' ),
  59. 'slug' => 'light-gray',
  60. 'color' => '#d9d9d9',
  61. ),
  62. array(
  63. 'name' => esc_html__( 'White', 'apostrophe-2' ),
  64. 'slug' => 'white',
  65. 'color' => '#ffffff',
  66. ),
  67. array(
  68. 'name' => esc_html__( 'Blue', 'apostrophe-2' ),
  69. 'slug' => 'blue',
  70. 'color' => '#159ae7',
  71. ),
  72. array(
  73. 'name' => esc_html__( 'Dark Blue', 'apostrophe-2' ),
  74. 'slug' => 'dark-blue',
  75. 'color' => '#362e77',
  76. ),
  77. )
  78. );
  79. /*
  80. * Let WordPress manage the document title.
  81. * By adding theme support, we declare that this theme does not use a
  82. * hard-coded <title> tag in the document head, and expect WordPress to
  83. * provide it for us.
  84. */
  85. add_theme_support( 'title-tag' );
  86. /*
  87. * Enable support for Post Thumbnails on posts and pages.
  88. *
  89. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  90. */
  91. add_theme_support( 'post-thumbnails' );
  92. set_post_thumbnail_size( 450, 450, true );
  93. add_image_size( 'apostrophe-2-featured', 930, 450, true );
  94. add_image_size( 'apostrophe-2-mini', 60, 60, true );
  95. add_image_size( 'apostrophe-2-gallery', 550, 550, true );
  96. register_nav_menus(
  97. array(
  98. 'menu-1' => esc_html__( 'Header Menu', 'apostrophe-2' ),
  99. )
  100. );
  101. /*
  102. * Switch default core markup for search form, comment form, and comments
  103. * to output valid HTML5.
  104. */
  105. add_theme_support(
  106. 'html5',
  107. array(
  108. 'comment-list',
  109. 'comment-form',
  110. 'search-form',
  111. 'gallery',
  112. 'caption',
  113. )
  114. );
  115. // Set up the WordPress core custom background feature.
  116. add_theme_support(
  117. 'custom-background',
  118. apply_filters(
  119. 'apostrophe_2_custom_background_args',
  120. array(
  121. 'default-color' => 'ffffff',
  122. 'default-image' => '',
  123. )
  124. )
  125. );
  126. // Enable support for custom logo.
  127. add_theme_support(
  128. 'custom-logo',
  129. array(
  130. 'height' => 300,
  131. 'width' => 1030,
  132. 'flex-height' => true,
  133. 'flex-width' => true,
  134. )
  135. );
  136. // Add theme support for selective refresh for widgets.
  137. add_theme_support( 'customize-selective-refresh-widgets' );
  138. }
  139. endif; // apostrophe_2_setup
  140. add_action( 'after_setup_theme', 'apostrophe_2_setup' );
  141. /**
  142. * Adjust content width for full-width page template
  143. */
  144. function apostrophe_2_adjusted_content_width() {
  145. global $content_width;
  146. if ( is_page_template( 'templates/full-width-page.php' ) ||
  147. ( ! is_active_sidebar( 'sidebar-1' ) && ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) ) ) {
  148. $content_width = 1060; /* pixels */
  149. }
  150. }
  151. add_action( 'template_redirect', 'apostrophe_2_adjusted_content_width', 0 );
  152. /**
  153. * Register lots of widget areas.
  154. *
  155. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  156. */
  157. function apostrophe_2_widgets_init() {
  158. register_sidebar(
  159. array(
  160. 'name' => esc_html__( 'Primary', 'apostrophe-2' ),
  161. 'id' => 'sidebar-1',
  162. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  163. 'after_widget' => '</aside>',
  164. 'before_title' => '<h2 class="widget-title">',
  165. 'after_title' => '</h2>',
  166. )
  167. );
  168. register_sidebar(
  169. array(
  170. 'name' => esc_html__( 'Secondary', 'apostrophe-2' ),
  171. 'id' => 'sidebar-2',
  172. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  173. 'after_widget' => '</aside>',
  174. 'before_title' => '<h2 class="widget-title">',
  175. 'after_title' => '</h2>',
  176. )
  177. );
  178. register_sidebar(
  179. array(
  180. 'name' => esc_html__( 'Tertiary', 'apostrophe-2' ),
  181. 'id' => 'sidebar-3',
  182. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  183. 'after_widget' => '</aside>',
  184. 'before_title' => '<h2 class="widget-title">',
  185. 'after_title' => '</h2>',
  186. )
  187. );
  188. register_sidebar(
  189. array(
  190. 'name' => esc_html__( 'Footer Sidebar', 'apostrophe-2' ),
  191. 'id' => 'sidebar-4',
  192. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  193. 'after_widget' => '</aside>',
  194. 'before_title' => '<h3 class="widget-title">',
  195. 'after_title' => '</h3>',
  196. )
  197. );
  198. }
  199. add_action( 'widgets_init', 'apostrophe_2_widgets_init' );
  200. /**
  201. * Load all Google fonts used in theme
  202. */
  203. function apostrophe_2_fonts_url() {
  204. $fonts_url = '';
  205. /* Translators: If there are characters in your language that are not
  206. * supported by PT Serif, translate this to 'off'. Do not translate
  207. * into your own language.
  208. */
  209. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'apostrophe-2' );
  210. /* Translators: If there are characters in your language that are not
  211. * supported by Open Sans, translate this to 'off'. Do not translate
  212. * into your own language.
  213. */
  214. $open_sans = _x( 'on', 'Open Sans font: on or off', 'apostrophe-2' );
  215. if ( 'off' !== $pt_serif || 'off' !== $open_sans ) :
  216. $font_families = array();
  217. if ( 'off' !== $pt_serif ) {
  218. $font_families[] = 'PT Serif:400,400italic,700,700italic';
  219. }
  220. if ( 'off' !== $open_sans ) {
  221. $font_families[] = 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic';
  222. }
  223. /**
  224. * A filter to enable child themes to add/change/omit font families.
  225. *
  226. * @param array $font_families An array of font families to be imploded for the Google Font API
  227. */
  228. $font_families = apply_filters( 'included_google_font_families', $font_families );
  229. $query_args = array(
  230. 'family' => urlencode( implode( '|', $font_families ) ),
  231. 'subset' => urlencode( 'latin,latin-ext,cyrillic' ),
  232. );
  233. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  234. endif;
  235. return $fonts_url;
  236. }
  237. /**
  238. * Enqueue scripts and styles.
  239. */
  240. function apostrophe_2_scripts() {
  241. // Gutenberg styles
  242. wp_enqueue_style( 'apostrophe-2-blocks', get_template_directory_uri() . '/css/blocks.css' );
  243. wp_enqueue_style( 'apostrophe-2-style', get_stylesheet_uri(), array(), '20140520' );
  244. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/css/genericons.css', array(), '20131222' );
  245. wp_enqueue_style( 'apostrophe-2-fonts', apostrophe_2_fonts_url(), array(), null );
  246. wp_enqueue_script( 'apostrophe-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20150605', true );
  247. wp_enqueue_script( 'apostrophe-2-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20161104', true );
  248. wp_enqueue_script( 'apostrophe-2', get_template_directory_uri() . '/js/apostrophe.js', array( 'jquery' ), '20150226', true );
  249. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  250. wp_enqueue_script( 'comment-reply' );
  251. }
  252. wp_localize_script(
  253. 'apostrophe-2-navigation',
  254. 'screenReaderText',
  255. array(
  256. 'expand' => esc_html__( 'expand child menu', 'apostrophe-2' ),
  257. 'collapse' => esc_html__( 'collapse child menu', 'apostrophe-2' ),
  258. )
  259. );
  260. }
  261. add_action( 'wp_enqueue_scripts', 'apostrophe_2_scripts' );
  262. /**
  263. * Gutenberg Editor Styles
  264. */
  265. function apostrophe_2_editor_styles() {
  266. wp_enqueue_style( 'apostrophe-2-editor-block-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  267. wp_enqueue_style( 'apostrophe-2-fonts', apostrophe_2_fonts_url(), array(), null );
  268. }
  269. add_action( 'enqueue_block_editor_assets', 'apostrophe_2_editor_styles' );
  270. /**
  271. * Use a specific size for the gallery shortcode.
  272. *
  273. * Unless a size is explicitly provided in the shortcode,
  274. * use a size registered with the theme if the number of columns
  275. * is more than a single one.
  276. */
  277. function apostrophe_2_shortcode_atts_gallery( $out, $pairs, $atts ) {
  278. if ( empty( $atts['size'] ) && $out['columns'] >= 2 ) {
  279. $out['size'] = 'apostrophe-2-gallery';
  280. }
  281. return $out;
  282. }
  283. add_filter( 'shortcode_atts_gallery', 'apostrophe_2_shortcode_atts_gallery', 10, 3 );
  284. /**
  285. * Add a body class to indicate when the user is viewing the site via the Customizer.
  286. * This allows us to hide the star-to-tag-as-featured-content buttons, since they're
  287. * largely irrelevant here, and may confuse users.
  288. */
  289. function apostrophe_2_body_class( $classes ) {
  290. if ( ! is_active_sidebar( 'sidebar-1' ) && ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) ) {
  291. $classes[] = 'apostrophe-2-no-sidebar';
  292. }
  293. if ( function_exists( 'jetpack_social_menu' ) && get_theme_mod( 'apostrophe_2_mobile_social' ) == 1 ) {
  294. $classes[] = 'show-mobile-social-menu';
  295. }
  296. return $classes;
  297. }
  298. add_filter( 'body_class', 'apostrophe_2_body_class' );
  299. /**
  300. * Remove the "home" link from the default menu.
  301. */
  302. function apostrophe_2_page_menu_args( $args ) {
  303. $args['show_home'] = true;
  304. return $args;
  305. }
  306. add_filter( 'wp_page_menu_args', 'apostrophe_2_page_menu_args' );
  307. /**
  308. * Implement the Custom Header feature.
  309. */
  310. require get_template_directory() . '/inc/custom-header.php';
  311. /**
  312. * Custom template tags for this theme.
  313. */
  314. require get_template_directory() . '/inc/template-tags.php';
  315. /**
  316. * Customizer additions.
  317. */
  318. require get_template_directory() . '/inc/customizer.php';
  319. /**
  320. * Load Jetpack compatibility file.
  321. */
  322. require get_template_directory() . '/inc/jetpack.php';
  323. /**
  324. * Featured post stuff
  325. */
  326. require get_template_directory() . '/inc/featured-posts.php';