functions.php 11 KB

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