functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * TextBook functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package TextBook
  8. */
  9. if ( ! function_exists( 'textbook_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 textbook_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 'textbook' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'textbook', 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. // Adds theme-specific images sizes
  41. add_image_size( 'textbook-thumbnail-avatar', 100, 100, true );
  42. add_image_size( 'textbook-featured-content-image', 600, 600, true );
  43. add_image_size( 'textbook-featured-content-image-full', 1148, 600, true );
  44. /**
  45. * This theme uses wp_nav_menu() in two locations.
  46. */
  47. register_nav_menus( array(
  48. 'header' => __( 'Header', 'textbook' ),
  49. 'footer' => __( 'Footer', 'textbook' ),
  50. ) );
  51. /*
  52. * Switch default core markup for search form, comment form, and comments
  53. * to output valid HTML5.
  54. */
  55. add_theme_support( 'html5', array(
  56. 'search-form',
  57. 'comment-form',
  58. 'comment-list',
  59. 'gallery',
  60. 'caption',
  61. ) );
  62. }
  63. endif;
  64. add_action( 'after_setup_theme', 'textbook_setup' );
  65. /**
  66. * Set the content width in pixels, based on the theme's design and stylesheet.
  67. *
  68. * Priority 0 to make it available to lower priority callbacks.
  69. *
  70. * @global int $content_width
  71. */
  72. function textbook_content_width() {
  73. $GLOBALS['content_width'] = apply_filters( 'textbook_content_width', 900 );
  74. }
  75. add_action( 'after_setup_theme', 'textbook_content_width', 0 );
  76. /**
  77. * Set theme date format to TextBook suggested default.
  78. */
  79. function textbook_update_date_format() {
  80. update_option( 'date_format', 'j M Y' );
  81. }
  82. add_action( 'after_switch_theme', 'textbook_update_date_format', 0 );
  83. /**
  84. * Register widget area.
  85. *
  86. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  87. */
  88. function textbook_widgets_init() {
  89. register_sidebar( array(
  90. 'name' => esc_html__( 'Sidebar', 'textbook' ),
  91. 'id' => 'sidebar-1',
  92. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  93. 'after_widget' => '</section>',
  94. 'before_title' => '<h2 class="widget-title">',
  95. 'after_title' => '</h2>',
  96. ) );
  97. register_sidebar( array(
  98. 'name' => esc_html__( 'Footer Sidebar', 'textbook' ),
  99. 'id' => 'sidebar-2',
  100. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  101. 'after_widget' => '</section>',
  102. 'before_title' => '<h2 class="widget-title">',
  103. 'after_title' => '</h2>',
  104. ) );
  105. }
  106. add_action( 'widgets_init', 'textbook_widgets_init' );
  107. /**
  108. * Output Libre Franklin Pro Google Font URL
  109. *
  110. * @link https://fonts.google.com/specimen/Libre+Franklin/
  111. * @return string
  112. */
  113. function textbook_libre_franklin_url() {
  114. $libre_franklin_font_url = '';
  115. /* translators: If there are characters in your language that are not supported
  116. * by Libre Franklin, translate this to 'off'. Do not translate into your own language.
  117. */
  118. if ( 'off' !== esc_html_x( 'on', 'Libre Franklin font: on or off', 'textbook' ) ) {
  119. $subsets = 'latin,latin-ext';
  120. /* translators: To add an additional Libre Franklin character subset specific to your language,
  121. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  122. */
  123. $subset = esc_html_x( 'no-subset', 'Libre Franklin font: add new subset (greek, cyrillic, vietnamese)', 'textbook' );
  124. if ( 'cyrillic' === $subset ) {
  125. $subsets .= ',cyrillic,cyrillic-ext';
  126. } elseif ( 'greek' === $subset ) {
  127. $subsets .= ',greek,greek-ext';
  128. } elseif ( 'vietnamese' === $subset ) {
  129. $subsets .= ',vietnamese';
  130. }
  131. $libre_franklin_font_url = add_query_arg( 'family', 'Libre Franklin:300,500,600,300italic,600italic', '//fonts.googleapis.com/css' );
  132. $libre_franklin_font_url = add_query_arg( 'subset', $subsets, $libre_franklin_font_url );
  133. }
  134. return $libre_franklin_font_url;
  135. }
  136. /**
  137. * Output Playfair Display Google Font URL
  138. *
  139. * @link https://fonts.google.com/specimen/Playfair+Display+SC/
  140. * @return string
  141. */
  142. function textbook_playfair_display_url() {
  143. $playfair_display_font_url = '';
  144. /* translators: If there are characters in your language that are not supported
  145. * by Playfair Display SC, translate this to 'off'. Do not translate into your own language.
  146. */
  147. if ( 'off' !== esc_html_x( 'on', 'Playfair Display font: on or off', 'textbook' ) ) {
  148. $subsets = 'latin,latin-ext';
  149. /* translators: To add an additional Playfair Display SC character subset specific to your language,
  150. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  151. */
  152. $subset = esc_html_x( 'no-subset', 'Playfair Display font: add new subset (greek, cyrillic, vietnamese)', 'textbook' );
  153. if ( 'cyrillic' === $subset ) {
  154. $subsets .= ',cyrillic,cyrillic-ext';
  155. } elseif ( 'greek' === $subset ) {
  156. $subsets .= ',greek,greek-ext';
  157. } elseif ( 'vietnamese' === $subset ) {
  158. $subsets .= ',vietnamese';
  159. }
  160. $playfair_display_font_url = add_query_arg( 'family', 'Playfair Display:400i', '//fonts.googleapis.com/css' );
  161. $playfair_display_font_url = add_query_arg( 'subset', $subsets, $playfair_display_font_url );
  162. }
  163. return $playfair_display_font_url;
  164. }
  165. /**
  166. * Output Playfair Display Small Caps Google Font URL
  167. *
  168. * @link https://fonts.google.com/specimen/Playfair+Display+SC/
  169. * @return string
  170. */
  171. function textbook_playfair_display_sc_url() {
  172. $playfair_display_sc_font_url = '';
  173. /* translators: If there are characters in your language that are not supported
  174. * by Playfair Display SC, translate this to 'off'. Do not translate into your own language.
  175. */
  176. if ( 'off' !== esc_html_x( 'on', 'Playfair Display SC font: on or off', 'textbook' ) ) {
  177. $subsets = 'latin,latin-ext';
  178. /* translators: To add an additional Playfair Display SC character subset specific to your language,
  179. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  180. */
  181. $subset = esc_html_x( 'no-subset', 'Playfair Display SC font: add new subset (greek, cyrillic, vietnamese)', 'textbook' );
  182. if ( 'cyrillic' === $subset ) {
  183. $subsets .= ',cyrillic,cyrillic-ext';
  184. } elseif ( 'greek' === $subset ) {
  185. $subsets .= ',greek,greek-ext';
  186. } elseif ( 'vietnamese' === $subset ) {
  187. $subsets .= ',vietnamese';
  188. }
  189. $playfair_display_sc_font_url = add_query_arg( 'family', 'Playfair Display SC:700', '//fonts.googleapis.com/css' );
  190. $playfair_display_sc_font_url = add_query_arg( 'subset', $subsets, $playfair_display_sc_font_url );
  191. }
  192. return $playfair_display_sc_font_url;
  193. }
  194. /*
  195. * Enqueue scripts and styles.
  196. */
  197. function textbook_scripts() {
  198. /*
  199. * Styles
  200. */
  201. // Libre Franklin font
  202. wp_register_style( 'textbook-libre-franklin', textbook_libre_franklin_url(), array(), null );
  203. wp_enqueue_style( 'textbook-libre-franklin' );
  204. // Playfair Display font
  205. wp_register_style( 'textbook-playfair-display', textbook_playfair_display_url(), array(), null );
  206. wp_enqueue_style( 'textbook-playfair-display' );
  207. // Playfair Display Small Caps font
  208. wp_register_style( 'textbook-playfair-display-sc', textbook_playfair_display_sc_url(), array(), null );
  209. wp_enqueue_style( 'textbook-playfair-display-sc' );
  210. // Textbook Stylesheet
  211. wp_enqueue_style( 'textbook-style', get_stylesheet_uri() );
  212. /*
  213. * Scripts
  214. */
  215. // Flexslider
  216. wp_enqueue_script( 'textbook-flexslider', get_template_directory_uri() . '/assets/js/jquery.flexslider.js', array( 'jquery' ), '2.6.1', true );
  217. // General functions
  218. wp_enqueue_script( 'textbook-functions', get_template_directory_uri() . '/assets/js/functions.js', array( 'jquery' ), '20160624', true );
  219. // Navigation
  220. wp_enqueue_script( 'textbook-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array( 'jquery' ), '20151215', true );
  221. // Skip link
  222. wp_enqueue_script( 'textbook-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  223. // Threaded comments
  224. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  225. wp_enqueue_script( 'comment-reply' );
  226. }
  227. // Menu toggle text
  228. wp_localize_script( 'textbook-navigation', 'textBookMenuToggleText', array(
  229. 'menu' => esc_html__( 'Menu', 'textbook' ),
  230. 'close' => esc_html__( 'Close', 'textbook' ),
  231. ) );
  232. // Expand collapse menu text
  233. wp_localize_script( 'textbook-navigation', 'textBookScreenReaderText', array(
  234. 'expand' => esc_html__( 'expand child menu', 'textbook' ),
  235. 'collapse' => esc_html__( 'collapse child menu', 'textbook' ),
  236. ) );
  237. // Search toggle text
  238. wp_localize_script( 'textbook-navigation', 'textBookSearchToggleText', array(
  239. 'search' => esc_html__( 'Search', 'textbook' ),
  240. 'close' => esc_html__( 'Close', 'textbook' )
  241. ) );
  242. }
  243. add_action( 'wp_enqueue_scripts', 'textbook_scripts' );
  244. /*
  245. * Check whether the browser supports JavaScript.
  246. */
  247. function textbook_html_js_class () {
  248. echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>'. "\n";
  249. }
  250. add_action( 'wp_head', 'textbook_html_js_class', 1 );
  251. /*
  252. * Implement the Custom Header feature.
  253. */
  254. require get_template_directory() . '/inc/custom-header.php';
  255. /*
  256. * Custom template tags for this theme.
  257. */
  258. require get_template_directory() . '/inc/template-tags.php';
  259. /*
  260. * Custom functions that act independently of the theme templates.
  261. */
  262. require get_template_directory() . '/inc/extras.php';
  263. /*
  264. * Customizer additions.
  265. */
  266. require get_template_directory() . '/inc/customizer.php';
  267. /*
  268. * Load Jetpack compatibility file.
  269. */
  270. require get_template_directory() . '/inc/jetpack.php';