functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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', array(
  41. array(
  42. 'name' => esc_html__( 'Black', 'apostrophe-2' ),
  43. 'slug' => 'black',
  44. 'color' => '#404040',
  45. ),
  46. array(
  47. 'name' => esc_html__( 'Dark Gray', 'apostrophe-2' ),
  48. 'slug' => 'dark-gray',
  49. 'color' => '#686868',
  50. ),
  51. array(
  52. 'name' => esc_html__( 'Medium Gray', 'apostrophe-2' ),
  53. 'slug' => 'medium-gray',
  54. 'color' => '#999999',
  55. ),
  56. array(
  57. 'name' => esc_html__( 'Light Gray', 'apostrophe-2' ),
  58. 'slug' => 'light-gray',
  59. 'color' => '#d9d9d9',
  60. ),
  61. array(
  62. 'name' => esc_html__( 'White', 'apostrophe-2' ),
  63. 'slug' => 'white',
  64. 'color' => '#ffffff',
  65. ),
  66. array(
  67. 'name' => esc_html__( 'Blue', 'apostrophe-2' ),
  68. 'slug' => 'blue',
  69. 'color' => '#159ae7',
  70. ),
  71. array(
  72. 'name' => esc_html__( 'Dark Blue', 'apostrophe-2' ),
  73. 'slug' => 'dark-blue',
  74. 'color' => '#362e77',
  75. )
  76. )
  77. );
  78. /*
  79. * Let WordPress manage the document title.
  80. * By adding theme support, we declare that this theme does not use a
  81. * hard-coded <title> tag in the document head, and expect WordPress to
  82. * provide it for us.
  83. */
  84. add_theme_support( 'title-tag' );
  85. /*
  86. * Enable support for Post Thumbnails on posts and pages.
  87. *
  88. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  89. */
  90. add_theme_support( 'post-thumbnails' );
  91. set_post_thumbnail_size( 450, 450, true );
  92. add_image_size( 'apostrophe-2-featured', 930, 450, true );
  93. add_image_size( 'apostrophe-2-mini', 60, 60, true );
  94. add_image_size( 'apostrophe-2-gallery', 550, 550, true );
  95. register_nav_menus( array(
  96. 'menu-1' => esc_html__( 'Header Menu', 'apostrophe-2' ),
  97. ) );
  98. /*
  99. * Switch default core markup for search form, comment form, and comments
  100. * to output valid HTML5.
  101. */
  102. add_theme_support( 'html5', array(
  103. 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption',
  104. ) );
  105. // Set up the WordPress core custom background feature.
  106. add_theme_support( 'custom-background', apply_filters( 'apostrophe_2_custom_background_args', array(
  107. 'default-color' => 'ffffff',
  108. 'default-image' => '',
  109. ) ) );
  110. // Enable support for custom logo.
  111. add_theme_support( 'custom-logo', array(
  112. 'height' => 300,
  113. 'width' => 1030,
  114. 'flex-height' => true,
  115. 'flex-width' => true
  116. ) );
  117. // Add theme support for selective refresh for widgets.
  118. add_theme_support( 'customize-selective-refresh-widgets' );
  119. }
  120. endif; // apostrophe_2_setup
  121. add_action( 'after_setup_theme', 'apostrophe_2_setup' );
  122. /**
  123. * Adjust content width for full-width page template
  124. */
  125. function apostrophe_2_adjusted_content_width() {
  126. global $content_width;
  127. if ( is_page_template( 'templates/full-width-page.php' ) ||
  128. ( ! is_active_sidebar( 'sidebar-1' ) && ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) ) ) {
  129. $content_width = 1060; /* pixels */
  130. }
  131. }
  132. add_action( 'template_redirect', 'apostrophe_2_adjusted_content_width', 0 );
  133. /**
  134. * Register lots of widget areas.
  135. *
  136. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  137. */
  138. function apostrophe_2_widgets_init() {
  139. register_sidebar( array(
  140. 'name' => esc_html__( 'Primary', 'apostrophe-2' ),
  141. 'id' => 'sidebar-1',
  142. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  143. 'after_widget' => '</aside>',
  144. 'before_title' => '<h2 class="widget-title">',
  145. 'after_title' => '</h2>',
  146. ) );
  147. register_sidebar( array(
  148. 'name' => esc_html__( 'Secondary', 'apostrophe-2' ),
  149. 'id' => 'sidebar-2',
  150. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  151. 'after_widget' => '</aside>',
  152. 'before_title' => '<h2 class="widget-title">',
  153. 'after_title' => '</h2>',
  154. ) );
  155. register_sidebar( array(
  156. 'name' => esc_html__( 'Tertiary', 'apostrophe-2' ),
  157. 'id' => 'sidebar-3',
  158. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  159. 'after_widget' => '</aside>',
  160. 'before_title' => '<h2 class="widget-title">',
  161. 'after_title' => '</h2>',
  162. ) );
  163. register_sidebar( array(
  164. 'name' => esc_html__( 'Footer Sidebar', 'apostrophe-2' ),
  165. 'id' => 'sidebar-4',
  166. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  167. 'after_widget' => '</aside>',
  168. 'before_title' => '<h3 class="widget-title">',
  169. 'after_title' => '</h3>',
  170. ) );
  171. }
  172. add_action( 'widgets_init', 'apostrophe_2_widgets_init' );
  173. /**
  174. * Load all Google fonts used in theme
  175. */
  176. function apostrophe_2_fonts_url() {
  177. $fonts_url = '';
  178. /* Translators: If there are characters in your language that are not
  179. * supported by PT Serif, translate this to 'off'. Do not translate
  180. * into your own language.
  181. */
  182. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'apostrophe-2' );
  183. /* Translators: If there are characters in your language that are not
  184. * supported by Open Sans, translate this to 'off'. Do not translate
  185. * into your own language.
  186. */
  187. $open_sans = _x( 'on', 'Open Sans font: on or off', 'apostrophe-2' );
  188. if ( 'off' !== $pt_serif || 'off' !== $open_sans ) :
  189. $font_families = array();
  190. if ( 'off' !== $pt_serif ) {
  191. $font_families[] = 'PT Serif:400,400italic,700,700italic';
  192. }
  193. if ( 'off' !== $open_sans ) {
  194. $font_families[] = 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic';
  195. }
  196. $query_args = array(
  197. 'family' => urlencode( implode( '|', $font_families ) ),
  198. 'subset' => urlencode( 'latin,latin-ext,cyrillic' ),
  199. );
  200. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  201. endif;
  202. return $fonts_url;
  203. }
  204. /**
  205. * Enqueue scripts and styles.
  206. */
  207. function apostrophe_2_scripts() {
  208. // Gutenberg styles
  209. wp_enqueue_style( 'apostrophe-2-blocks', get_template_directory_uri() . '/css/blocks.css' );
  210. wp_enqueue_style( 'apostrophe-2-style', get_stylesheet_uri(), array(), '20140520' );
  211. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/css/genericons.css', array(), '20131222' );
  212. wp_enqueue_style( 'apostrophe-2-fonts', apostrophe_2_fonts_url(), array(), null );
  213. wp_enqueue_script( 'apostrophe-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20150605', true );
  214. wp_enqueue_script( 'apostrophe-2-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20161104', true );
  215. wp_enqueue_script( 'apostrophe-2', get_template_directory_uri() . '/js/apostrophe.js', array( 'jquery' ), '20150226', true );
  216. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  217. wp_enqueue_script( 'comment-reply' );
  218. }
  219. wp_localize_script( 'apostrophe-2-navigation', 'screenReaderText', array(
  220. 'expand' => esc_html__( 'expand child menu', 'apostrophe-2' ),
  221. 'collapse' => esc_html__( 'collapse child menu', 'apostrophe-2' ),
  222. ) );
  223. }
  224. add_action( 'wp_enqueue_scripts', 'apostrophe_2_scripts' );
  225. /**
  226. * Gutenberg Editor Styles
  227. */
  228. function apostrophe_2_editor_styles() {
  229. wp_enqueue_style( 'apostrophe-2-editor-block-style', get_template_directory_uri() . '/css/editor-blocks.css');
  230. wp_enqueue_style( 'apostrophe-2-fonts', apostrophe_2_fonts_url(), array(), null );
  231. }
  232. add_action( 'enqueue_block_editor_assets', 'apostrophe_2_editor_styles' );
  233. /**
  234. * Use a specific size for the gallery shortcode.
  235. *
  236. * Unless a size is explicitly provided in the shortcode,
  237. * use a size registered with the theme if the number of columns
  238. * is more than a single one.
  239. */
  240. function apostrophe_2_shortcode_atts_gallery( $out, $pairs, $atts ) {
  241. if ( empty( $atts['size'] ) && $out['columns'] >= 2 ) {
  242. $out['size'] = 'apostrophe-2-gallery';
  243. }
  244. return $out;
  245. }
  246. add_filter( 'shortcode_atts_gallery', 'apostrophe_2_shortcode_atts_gallery', 10, 3 );
  247. /**
  248. * Add a body class to indicate when the user is viewing the site via the Customizer.
  249. * This allows us to hide the star-to-tag-as-featured-content buttons, since they're
  250. * largely irrelevant here, and may confuse users.
  251. */
  252. function apostrophe_2_body_class( $classes ) {
  253. if ( ! is_active_sidebar( 'sidebar-1' ) && ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) ) {
  254. $classes[] = 'apostrophe-2-no-sidebar';
  255. }
  256. return $classes;
  257. }
  258. add_filter( 'body_class', 'apostrophe_2_body_class' );
  259. /**
  260. * Remove the "home" link from the default menu.
  261. */
  262. function apostrophe_2_page_menu_args( $args ) {
  263. $args['show_home'] = true;
  264. return $args;
  265. }
  266. add_filter( 'wp_page_menu_args', 'apostrophe_2_page_menu_args' );
  267. /**
  268. * Implement the Custom Header feature.
  269. */
  270. require get_template_directory() . '/inc/custom-header.php';
  271. /**
  272. * Custom template tags for this theme.
  273. */
  274. require get_template_directory() . '/inc/template-tags.php';
  275. /**
  276. * Customizer additions.
  277. */
  278. require get_template_directory() . '/inc/customizer.php';
  279. /**
  280. * Load Jetpack compatibility file.
  281. */
  282. require get_template_directory() . '/inc/jetpack.php';
  283. /**
  284. * Featured post stuff
  285. */
  286. require get_template_directory() . '/inc/featured-posts.php';