functions.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. /**
  3. * Rebalance functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Rebalance
  8. */
  9. if ( ! function_exists( 'rebalance_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 rebalance_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 rebalance, use a find and replace
  22. * to change 'rebalance' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'rebalance', 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. // Add support for responsive embeds.
  35. add_theme_support( 'responsive-embeds' );
  36. // Add custom colors to Gutenberg
  37. add_theme_support(
  38. 'editor-color-palette', array(
  39. array(
  40. 'name' => esc_html__( 'Black', 'rebalance' ),
  41. 'slug' => 'black',
  42. 'color' => '#000000',
  43. ),
  44. array(
  45. 'name' => esc_html__( 'Dark Gray', 'rebalance' ),
  46. 'slug' => 'dark-gray',
  47. 'color' => '#666666',
  48. ),
  49. array(
  50. 'name' => esc_html__( 'Medium Gray', 'rebalance' ),
  51. 'slug' => 'medium-gray',
  52. 'color' => '#999999',
  53. ),
  54. array(
  55. 'name' => esc_html__( 'Light Gray', 'rebalance' ),
  56. 'slug' => 'light-gray',
  57. 'color' => '#cccccc',
  58. ),
  59. array(
  60. 'name' => esc_html__( 'White', 'rebalance' ),
  61. 'slug' => 'white',
  62. 'color' => '#ffffff',
  63. ),
  64. array(
  65. 'name' => esc_html__( 'Red', 'rebalance' ),
  66. 'slug' => 'red',
  67. 'color' => '#f35029',
  68. ),
  69. array(
  70. 'name' => esc_html__( 'Dark Red', 'rebalance' ),
  71. 'slug' => 'dark-red',
  72. 'color' => '#aa2e11',
  73. ),
  74. )
  75. );
  76. /**
  77. * Add support for core custom logo (replaces JetPack functionality)
  78. * - also see fallback in inc/jetpack.php
  79. */
  80. add_theme_support( 'custom-logo', array(
  81. 'height' => 80,
  82. 'width' => 80,
  83. 'flex-width' => true,
  84. 'header-text' => array(
  85. 'site-title',
  86. 'site-description'
  87. ),
  88. ) );
  89. /*
  90. * Enable support for Post Thumbnails on posts and pages.
  91. *
  92. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  93. */
  94. add_theme_support( 'post-thumbnails' );
  95. set_post_thumbnail_size( 720, 1200 );
  96. add_image_size( 'rebalance-archive', 560, 9999 );
  97. /*
  98. * This theme uses wp_nav_menu() in one location.
  99. */
  100. register_nav_menus( array(
  101. 'header' => esc_html__( 'Header Menu', 'rebalance' ),
  102. 'social' => esc_html__( 'Social Menu', 'rebalance' )
  103. ) );
  104. /*
  105. * Switch default core markup for search form, comment form, and comments
  106. * to output valid HTML5.
  107. */
  108. add_theme_support( 'html5', array(
  109. 'search-form',
  110. 'comment-form',
  111. 'comment-list',
  112. 'gallery',
  113. 'caption',
  114. ) );
  115. /*
  116. * Enable support for Post Formats.
  117. * See https://developer.wordpress.org/themes/functionality/post-formats/
  118. */
  119. add_theme_support( 'post-formats', array(
  120. 'aside',
  121. 'image',
  122. 'video',
  123. 'quote',
  124. 'link',
  125. ) );
  126. // Set up the WordPress core custom background feature.
  127. add_theme_support( 'custom-background', apply_filters( 'rebalance_custom_background_args', array(
  128. 'default-color' => 'ffffff',
  129. 'default-image' => '',
  130. ) ) );
  131. }
  132. endif; // rebalance_setup
  133. add_action( 'after_setup_theme', 'rebalance_setup' );
  134. /**
  135. * Set the content width in pixels, based on the theme's design and stylesheet.
  136. *
  137. * Priority 0 to make it available to lower priority callbacks.
  138. *
  139. * @global int $content_width
  140. */
  141. function rebalance_content_width() {
  142. $GLOBALS['content_width'] = apply_filters( 'rebalance_content_width', 1140 );
  143. }
  144. add_action( 'after_setup_theme', 'rebalance_content_width', 0 );
  145. /**
  146. * Register widget area.
  147. *
  148. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  149. */
  150. function rebalance_widgets_init() {
  151. register_sidebar( array(
  152. 'name' => esc_html__( 'Footer', 'rebalance' ),
  153. 'id' => 'sidebar-1',
  154. 'description' => '',
  155. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  156. 'after_widget' => '</aside>',
  157. 'before_title' => '<h2 class="widget-title">',
  158. 'after_title' => '</h2>',
  159. ) );
  160. }
  161. add_action( 'widgets_init', 'rebalance_widgets_init' );
  162. /**
  163. * Add Google webfonts
  164. *
  165. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  166. */
  167. function rebalance_fonts_url() {
  168. $fonts_url = '';
  169. /* Translators: If there are characters in your language that are not
  170. * supported by Lora, translate this to 'off'. Do not translate
  171. * into your own language.
  172. */
  173. $rubik = esc_html_x( 'on', 'Rubik font: on or off', 'rebalance' );
  174. /* Translators: If there are characters in your language that are not
  175. * supported by Open Sans, translate this to 'off'. Do not translate
  176. * into your own language.
  177. */
  178. $libre_baskerville = esc_html_x( 'on', 'Libre Baskerville font: on or off', 'rebalance' );
  179. if ( 'off' !== $rubik || 'off' !== $libre_baskerville ) {
  180. $font_families = array();
  181. if ( 'off' !== $rubik ) {
  182. $font_families[] = 'Rubik:400,500,700,900,400italic,700italic';
  183. }
  184. if ( 'off' !== $libre_baskerville ) {
  185. $font_families[] = 'Libre Baskerville:700,900,400italic';
  186. }
  187. $query_args = array(
  188. 'family' => urlencode( implode( '|', $font_families ) ),
  189. 'subset' => urlencode( 'latin,latin-ext' ),
  190. );
  191. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  192. }
  193. return esc_url_raw( $fonts_url );
  194. }
  195. /**
  196. * Enqueue scripts and styles.
  197. */
  198. function rebalance_scripts() {
  199. /**
  200. * Styles
  201. */
  202. wp_enqueue_style( 'rebalance-fonts', rebalance_fonts_url(), array(), null );
  203. wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/font-awesome/font-awesome.css', array(), '20151022' );
  204. wp_enqueue_style( 'rebalance-style', get_stylesheet_uri() );
  205. // Gutenberg styles
  206. wp_enqueue_style( 'rebalance-blocks', get_template_directory_uri() . '/blocks.css' );
  207. /**
  208. * Scripts
  209. */
  210. wp_enqueue_script( 'columnlist', get_template_directory_uri() . '/js/columnlist.js', array( 'jquery' ), '20151120', true );
  211. wp_enqueue_script( 'rebalance-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151112', true );
  212. wp_enqueue_script( 'rebalance-theme-scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery', 'columnlist', 'masonry' ), '20151130', true );
  213. wp_localize_script( 'rebalance-theme-scripts', 'Rebalance', array(
  214. 'is_rtl' => ( 'rtl' == get_option( 'text_direction' ) ) ? 1 : 0,
  215. ) );
  216. wp_enqueue_script( 'rebalance-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151112', true );
  217. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  218. wp_enqueue_script( 'comment-reply' );
  219. }
  220. wp_localize_script( 'rebalance-navigation', 'rebalanceScreenReaderText', array(
  221. 'expand' => esc_html__( 'expand child menu', 'rebalance' ),
  222. 'collapse' => esc_html__( 'collapse child menu', 'rebalance' ),
  223. ) );
  224. }
  225. add_action( 'wp_enqueue_scripts', 'rebalance_scripts' );
  226. /**
  227. * Gutenberg Editor Styles
  228. */
  229. function rebalance_editor_styles() {
  230. wp_enqueue_style( 'rebalance-editor-block-style', get_template_directory_uri() . '/editor-blocks.css');
  231. wp_enqueue_style( 'rebalance-fonts', rebalance_fonts_url(), array(), null );
  232. }
  233. add_action( 'enqueue_block_editor_assets', 'rebalance_editor_styles' );
  234. /**
  235. * Check whether the browser supports JavaScript
  236. */
  237. function rebalance_html_js_class () {
  238. echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>'. "\n";
  239. }
  240. add_action( 'wp_head', 'rebalance_html_js_class', 1 );
  241. /**
  242. * Implement the Custom Header feature.
  243. */
  244. require get_template_directory() . '/inc/custom-header.php';
  245. /**
  246. * Custom template tags for this theme.
  247. */
  248. require get_template_directory() . '/inc/template-tags.php';
  249. /**
  250. * Custom functions that act independently of the theme templates.
  251. */
  252. require get_template_directory() . '/inc/extras.php';
  253. /**
  254. * Customizer additions.
  255. */
  256. require get_template_directory() . '/inc/customizer.php';
  257. /**
  258. * Load Jetpack compatibility file.
  259. */
  260. require get_template_directory() . '/inc/jetpack.php';