functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. /**
  3. * components functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package AltoFocus
  8. */
  9. if ( ! function_exists( 'altofocus_setup' ) ) :
  10. /**
  11. * Sets up theme defaults and registers support for various WordPress features.
  12. *
  13. * Note that this function is hooked into the aftercomponentsetup_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 altofocus_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 'altofocus' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'altofocus', 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( 'altofocus-thumb-image', 640, 9999, false );
  41. add_image_size( 'altofocus-post-featured-image', 1200, 800, false );
  42. // This theme uses wp_nav_menu() in one location.
  43. register_nav_menus(
  44. array(
  45. 'menu-1' => esc_html__( 'Top', 'altofocus' ),
  46. )
  47. );
  48. /**
  49. * Add support for core custom logo.
  50. */
  51. add_theme_support(
  52. 'custom-logo',
  53. array(
  54. 'height' => 200,
  55. 'width' => 200,
  56. 'flex-width' => true,
  57. 'flex-height' => true,
  58. )
  59. );
  60. /*
  61. * Switch default core markup for search form, comment form, and comments
  62. * to output valid HTML5.
  63. */
  64. add_theme_support(
  65. 'html5',
  66. array(
  67. 'search-form',
  68. 'comment-form',
  69. 'comment-list',
  70. 'gallery',
  71. 'caption',
  72. )
  73. );
  74. // Set up the WordPress core custom background feature.
  75. add_theme_support(
  76. 'custom-background',
  77. apply_filters(
  78. 'altofocus_custom_background_args',
  79. array(
  80. 'default-color' => 'ffffff',
  81. 'default-image' => '',
  82. 'default-position-x' => 'center',
  83. 'default-position-y' => 'center',
  84. 'default-repeat' => 'no-repeat',
  85. 'default-attachment' => 'fixed',
  86. 'default-size' => 'cover',
  87. 'wp-head-callback' => 'altofocus_custom_background_cb',
  88. )
  89. )
  90. );
  91. // Add support for responsive embeds.
  92. add_theme_support( 'responsive-embeds' );
  93. // Add support for custom color scheme.
  94. add_theme_support(
  95. 'editor-color-palette',
  96. array(
  97. array(
  98. 'name' => esc_html__( 'Orange', 'altofocus' ),
  99. 'slug' => 'orange',
  100. 'color' => '#e38900',
  101. ),
  102. array(
  103. 'name' => esc_html__( 'Dark Gray', 'altofocus' ),
  104. 'slug' => 'dark-gray',
  105. 'color' => '#111',
  106. ),
  107. array(
  108. 'name' => esc_html__( 'Medium Gray', 'altofocus' ),
  109. 'slug' => 'medium-gray',
  110. 'color' => '#888',
  111. ),
  112. array(
  113. 'name' => esc_html__( 'Light Gray', 'altofocus' ),
  114. 'slug' => 'light-gray',
  115. 'color' => '#ccc',
  116. ),
  117. array(
  118. 'name' => esc_html__( 'White', 'altofocus' ),
  119. 'slug' => 'white',
  120. 'color' => '#fff',
  121. ),
  122. )
  123. );
  124. }
  125. endif;
  126. add_action( 'after_setup_theme', 'altofocus_setup' );
  127. /**
  128. * Set the content width in pixels, based on the theme's design and stylesheet.
  129. *
  130. * Priority 0 to make it available to lower priority callbacks.
  131. *
  132. * @global int $content_width
  133. */
  134. function altofocus_content_width() {
  135. $GLOBALS['content_width'] = apply_filters( 'altofocus_content_width', '770' );
  136. }
  137. add_action( 'after_setup_theme', 'altofocus_content_width', 0 );
  138. /**
  139. * Register widget area.
  140. *
  141. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  142. */
  143. function altofocus_widgets_init() {
  144. register_sidebar(
  145. array(
  146. 'name' => esc_html__( 'Footer', 'altofocus' ),
  147. 'id' => 'sidebar-1',
  148. 'description' => '',
  149. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  150. 'after_widget' => '</section>',
  151. 'before_title' => '<h2 class="widget-title">',
  152. 'after_title' => '</h2>',
  153. )
  154. );
  155. }
  156. add_action( 'widgets_init', 'altofocus_widgets_init' );
  157. /**
  158. * Output Libre Baskerville Google Font URL
  159. *
  160. * @link https://fonts.google.com/specimen/Libre+Baskerville/
  161. * @return string
  162. */
  163. function altofocus_libre_baskerville_url() {
  164. $libre_baskerville_font_url = '';
  165. /* translators: If there are characters in your language that are not supported
  166. * by Libre Baskerville, translate this to 'off'. Do not translate into your own language.
  167. */
  168. if ( 'off' !== esc_html_x( 'on', 'Libre Baskerville font: on or off', 'altofocus' ) ) {
  169. $subsets = 'latin,latin-ext';
  170. /* translators: To add an additional Libre Baskerville character subset specific to your language,
  171. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  172. */
  173. $subset = esc_html_x( 'no-subset', 'Libre Baskerville font: add new subset (greek, cyrillic, vietnamese)', 'altofocus' );
  174. if ( 'cyrillic' === $subset ) {
  175. $subsets .= ',cyrillic,cyrillic-ext';
  176. } elseif ( 'greek' === $subset ) {
  177. $subsets .= ',greek,greek-ext';
  178. } elseif ( 'vietnamese' === $subset ) {
  179. $subsets .= ',vietnamese';
  180. }
  181. $libre_baskerville_font_url = add_query_arg( 'family', 'Libre Baskerville:400,400i,700', '//fonts.googleapis.com/css' );
  182. $libre_baskerville_font_url = add_query_arg( 'subset', $subsets, $libre_baskerville_font_url );
  183. }
  184. return $libre_baskerville_font_url;
  185. }
  186. /**
  187. * Output Karla Google Font URL
  188. *
  189. * @link https://fonts.google.com/specimen/Karla/
  190. * @return string
  191. */
  192. function altofocus_karla_url() {
  193. $karla_font_url = '';
  194. /* translators: If there are characters in your language that are not supported
  195. * by Karla SC, translate this to 'off'. Do not translate into your own language.
  196. */
  197. if ( 'off' !== esc_html_x( 'on', 'Karla font: on or off', 'altofocus' ) ) {
  198. $subsets = 'latin,latin-ext';
  199. /* translators: To add an additional Karla SC character subset specific to your language,
  200. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  201. */
  202. $subset = esc_html_x( 'no-subset', 'Karla font: add new subset (greek, cyrillic, vietnamese)', 'altofocus' );
  203. if ( 'cyrillic' === $subset ) {
  204. $subsets .= ',cyrillic,cyrillic-ext';
  205. } elseif ( 'greek' === $subset ) {
  206. $subsets .= ',greek,greek-ext';
  207. } elseif ( 'vietnamese' === $subset ) {
  208. $subsets .= ',vietnamese';
  209. }
  210. $karla_font_url = add_query_arg( 'family', 'Karla:400,400i,700', '//fonts.googleapis.com/css' );
  211. $karla_font_url = add_query_arg( 'subset', $subsets, $karla_font_url );
  212. }
  213. return $karla_font_url;
  214. }
  215. /**
  216. * Enqueue scripts and styles.
  217. */
  218. function altofocus_scripts() {
  219. /*
  220. * Styles
  221. */
  222. // Libre Franklin font
  223. wp_enqueue_style( 'altofocus-libre-baskerville', altofocus_libre_baskerville_url(), array(), null );
  224. // Karla font
  225. wp_enqueue_style( 'altofocus-karla', altofocus_karla_url(), array(), null );
  226. // Stylesheet
  227. wp_enqueue_style( 'altofocus-style', get_stylesheet_uri() );
  228. // Block stylesheets
  229. wp_enqueue_style( 'altofocus-block-style', get_template_directory_uri() . '/assets/stylesheets/blocks.css', array( 'altofocus-style' ), '20181018' );
  230. /*
  231. * Scripts
  232. */
  233. // Flexslider
  234. wp_enqueue_script( 'altofocus-flexslider', get_template_directory_uri() . '/assets/js/jquery.flexslider.js', array( 'jquery' ), '2.6.1', true );
  235. // Column list
  236. wp_enqueue_script( 'altofocus-columnlist', get_template_directory_uri() . '/assets/js/columnlist.js', array( 'jquery' ), '20151120', true );
  237. // Navigation
  238. wp_enqueue_script( 'altofocus-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array( 'jquery' ), '20170301', true );
  239. // Images Loaded
  240. wp_enqueue_script( 'altofocus-imagesloaded', get_template_directory_uri() . '/assets/js/imagesloaded.pkgd.js', array( 'jquery' ), '4.1.0', true );
  241. // Isotope
  242. wp_enqueue_script( 'altofocus-isotope', get_template_directory_uri() . '/assets/js/isotope.pkgd.js', array( 'jquery', 'altofocus-imagesloaded' ), '3.0.1', true );
  243. // Grid setup
  244. wp_enqueue_script( 'altofocus-grid', get_template_directory_uri() . '/assets/js/grid.js', array( 'jquery', 'altofocus-imagesloaded', 'altofocus-isotope' ), '20170301', true );
  245. // AltoFocus Scripts
  246. wp_enqueue_script( 'altofocus-theme-scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery', 'altofocus-columnlist', 'altofocus-grid' ), '20170301', true );
  247. // Skip Link Focus Fix
  248. wp_enqueue_script( 'altofocus-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20170301', true );
  249. // Comment Reply Animation
  250. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  251. wp_enqueue_script( 'comment-reply' );
  252. }
  253. // Screenreader text
  254. wp_localize_script(
  255. 'altofocus-navigation',
  256. 'altoFocusScreenReaderText',
  257. array(
  258. 'expand' => esc_html__( 'expand child menu', 'altofocus' ),
  259. 'collapse' => esc_html__( 'collapse child menu', 'altofocus' ),
  260. )
  261. );
  262. // Flexslider text
  263. wp_localize_script(
  264. 'altofocus-flexslider',
  265. 'altoFocusFlexSliderText',
  266. array(
  267. 'next' => esc_html__( 'Next', 'altofocus' ),
  268. 'previous' => esc_html__( 'Previous', 'altofocus' ),
  269. )
  270. );
  271. }
  272. add_action( 'wp_enqueue_scripts', 'altofocus_scripts' );
  273. /**
  274. * Enqueue editor styles for Gutenberg
  275. */
  276. function altofocus_block_editor_styles() {
  277. // Block styles.
  278. wp_enqueue_style( 'altofocus-block-editor-style', get_template_directory_uri() . '/assets/stylesheets/editor-blocks.css' );
  279. // Libre Franklin font
  280. wp_enqueue_style( 'altofocus-libre-baskerville', altofocus_libre_baskerville_url(), array(), null );
  281. // Karla font
  282. wp_enqueue_style( 'altofocus-karla', altofocus_karla_url(), array(), null );
  283. }
  284. add_action( 'enqueue_block_editor_assets', 'altofocus_block_editor_styles' );
  285. /**
  286. * Check whether the browser supports JavaScript
  287. */
  288. function altofocus_html_js_class() {
  289. echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>' . "\n";
  290. }
  291. add_action( 'wp_head', 'altofocus_html_js_class', 1 );
  292. /**
  293. * Custom template tags for this theme.
  294. */
  295. require get_template_directory() . '/inc/template-tags.php';
  296. /**
  297. * Custom functions that act independently of the theme templates.
  298. */
  299. require get_template_directory() . '/inc/extras.php';
  300. /**
  301. * Customizer additions.
  302. */
  303. require get_template_directory() . '/inc/customizer.php';
  304. /**
  305. * Load Jetpack compatibility file.
  306. */
  307. require get_template_directory() . '/inc/jetpack.php';