functions.php 9.1 KB

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