functions.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /**
  3. * button functions and definitions
  4. *
  5. * @package Button 2
  6. */
  7. if ( ! function_exists( 'button_2_setup' ) ) :
  8. /**
  9. * Sets up theme defaults and registers support for various WordPress features.
  10. *
  11. * Note that this function is hooked into the after_setup_theme hook, which
  12. * runs before the init hook. The init hook is too late for some features, such
  13. * as indicating support for post thumbnails.
  14. */
  15. function button_2_setup() {
  16. /*
  17. * Make theme available for translation.
  18. * Translations can be filed in the /languages/ directory.
  19. * If you're building a theme based on button, use a find and replace
  20. * to change 'button-2' to the name of your theme in all the template files
  21. */
  22. load_theme_textdomain( 'button-2', get_template_directory() . '/languages' );
  23. // Add default posts and comments RSS feed links to head.
  24. add_theme_support( 'automatic-feed-links' );
  25. /*
  26. * Let WordPress manage the document title.
  27. * By adding theme support, we declare that this theme does not use a
  28. * hard-coded <title> tag in the document head, and expect WordPress to
  29. * provide it for us.
  30. */
  31. add_theme_support( 'title-tag' );
  32. /*
  33. * Enable support for Post Thumbnails on posts and pages.
  34. *
  35. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  36. */
  37. add_theme_support( 'post-thumbnails' );
  38. add_image_size( 'button-2-featured', '982', '9999' );
  39. // This theme uses wp_nav_menu() in two locations.
  40. register_nav_menus(
  41. array(
  42. 'menu-1' => esc_html__( 'Header', 'button-2' ),
  43. )
  44. );
  45. /*
  46. * Switch default core markup for search form, comment form, and comments
  47. * to output valid HTML5.
  48. */
  49. add_theme_support(
  50. 'html5',
  51. array(
  52. 'search-form',
  53. 'comment-form',
  54. 'comment-list',
  55. 'gallery',
  56. 'caption',
  57. )
  58. );
  59. // Enable support for custom logo.
  60. add_theme_support(
  61. 'custom-logo',
  62. array(
  63. 'height' => 300,
  64. 'width' => 1200,
  65. 'flex-height' => true,
  66. 'flex-width' => true,
  67. )
  68. );
  69. // Add theme support for selective refresh for widgets.
  70. add_theme_support( 'customize-selective-refresh-widgets' );
  71. // Set up the WordPress core custom background feature.
  72. add_theme_support(
  73. 'custom-background',
  74. apply_filters(
  75. 'button_2_custom_background_args',
  76. array(
  77. 'default-color' => 'f8f8f8',
  78. /*
  79. * We're using a unique filename for the background image
  80. * to avoid users uploading a file with the same filename
  81. * and avoiding conflict with the `user-background` body_class
  82. * in inc/extras.php and assets/js/customizer.js
  83. */
  84. 'default-image' => esc_url( get_template_directory_uri() ) . '/img/buttonbg20170303.png',
  85. )
  86. )
  87. );
  88. // Add support for wide images in Gutenberg
  89. add_theme_support( 'align-wide' );
  90. // Add support for responsive embeds.
  91. add_theme_support( 'responsive-embeds' );
  92. }
  93. endif; // button_2_setup
  94. add_action( 'after_setup_theme', 'button_2_setup' );
  95. /**
  96. * Set the content width in pixels, based on the theme's design and stylesheet.
  97. *
  98. * Priority 0 to make it available to lower priority callbacks.
  99. *
  100. * @global int $content_width
  101. */
  102. function button_2_content_width() {
  103. $GLOBALS['content_width'] = apply_filters( 'button_2_content_width', 663 );
  104. }
  105. add_action( 'after_setup_theme', 'button_2_content_width', 0 );
  106. /**
  107. * Adjust content width for full-width page template
  108. */
  109. function button_2_adjusted_content_width() {
  110. global $content_width;
  111. if ( is_page_template( 'templates/full-width-page.php' ) || ! is_active_sidebar( 'sidebar-1' ) ) {
  112. $content_width = 982;
  113. }
  114. }
  115. add_action( 'template_redirect', 'button_2_adjusted_content_width', 0 );
  116. /**
  117. * Register widget area.
  118. *
  119. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  120. */
  121. function button_2_widgets_init() {
  122. register_sidebar(
  123. array(
  124. 'name' => esc_html__( 'Sidebar', 'button-2' ),
  125. 'id' => 'sidebar-1',
  126. 'description' => '',
  127. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  128. 'after_widget' => '</aside>',
  129. 'before_title' => '<h1 class="widget-title">',
  130. 'after_title' => '</h1>',
  131. )
  132. );
  133. register_sidebar(
  134. array(
  135. 'name' => esc_html__( 'Footer 1', 'button-2' ),
  136. 'id' => 'sidebar-2',
  137. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  138. 'after_widget' => '</aside>',
  139. 'before_title' => '<h1 class="widget-title">',
  140. 'after_title' => '</h1>',
  141. )
  142. );
  143. register_sidebar(
  144. array(
  145. 'name' => esc_html__( 'Footer 2', 'button-2' ),
  146. 'id' => 'sidebar-3',
  147. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  148. 'after_widget' => '</aside>',
  149. 'before_title' => '<h1 class="widget-title">',
  150. 'after_title' => '</h1>',
  151. )
  152. );
  153. register_sidebar(
  154. array(
  155. 'name' => esc_html__( 'Footer 3', 'button-2' ),
  156. 'id' => 'sidebar-4',
  157. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  158. 'after_widget' => '</aside>',
  159. 'before_title' => '<h1 class="widget-title">',
  160. 'after_title' => '</h1>',
  161. )
  162. );
  163. }
  164. add_action( 'widgets_init', 'button_2_widgets_init' );
  165. /**
  166. * Enqueue scripts and styles.
  167. */
  168. function button_2_scripts() {
  169. wp_enqueue_style( 'button-2-style', get_stylesheet_uri() );
  170. wp_enqueue_style( 'button-2-fonts', button_2_fonts_url(), array(), null );
  171. wp_enqueue_style( 'button-2-blocks', get_template_directory_uri() . '/blocks.css' );
  172. wp_enqueue_script( 'button-2-scripts', get_template_directory_uri() . '/assets/js/main.js', array( 'jquery' ), '20211207', true );
  173. wp_enqueue_script( 'button-2-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  174. wp_enqueue_script( 'button-2-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  175. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  176. wp_enqueue_script( 'comment-reply' );
  177. }
  178. }
  179. add_action( 'wp_enqueue_scripts', 'button_2_scripts' );
  180. /**
  181. * Register Google Fonts
  182. */
  183. function button_2_fonts_url() {
  184. $fonts_url = '';
  185. /* Translators: If there are characters in your language that are not
  186. * supported by Lato, translate this to 'off'. Do not translate
  187. * into your own language.
  188. */
  189. $lato = esc_html_x( 'on', 'Lato font: on or off', 'button-2' );
  190. /* Translators: If there are characters in your language that are not
  191. * supported by Lora, translate this to 'off'. Do not translate
  192. * into your own language.
  193. */
  194. $lora = esc_html_x( 'on', 'Lora font: on or off', 'button-2' );
  195. if ( 'off' !== $lato || 'off' !== $lora ) {
  196. $font_families = array();
  197. if ( 'off' !== $lato ) {
  198. $font_families[] = 'Lato:400,300,300italic,400italic,700,700italic';
  199. }
  200. if ( 'off' !== $lora ) {
  201. $font_families[] = 'Lora:400italic,700italic';
  202. }
  203. /**
  204. * A filter to enable child themes to add/change/omit font families.
  205. *
  206. * @param array $font_families An array of font families to be imploded for the Google Font API
  207. */
  208. $font_families = apply_filters( 'included_google_font_families', $font_families );
  209. $query_args = array(
  210. 'family' => urlencode( implode( '|', $font_families ) ),
  211. 'subset' => urlencode( 'latin,latin-ext' ),
  212. );
  213. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  214. }
  215. return $fonts_url;
  216. }
  217. /**
  218. * Gutenberg Editor Styles
  219. */
  220. function button_2_editor_styles() {
  221. // Load fonts.
  222. wp_enqueue_style( 'button-2-fonts', button_2_fonts_url() );
  223. // Load block editor styles.
  224. wp_enqueue_style( 'button-2-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  225. // Load option for 'Fancy' image class.
  226. wp_enqueue_script( 'button-2-block-customization', get_template_directory_uri() . '/assets/js/block-variations.js', array( 'wp-blocks' ), '20181211', true );
  227. }
  228. add_action( 'enqueue_block_editor_assets', 'button_2_editor_styles' );
  229. /**
  230. * Implement the Custom Header feature.
  231. */
  232. require get_template_directory() . '/inc/custom-header.php';
  233. /**
  234. * Custom template tags for this theme.
  235. */
  236. require get_template_directory() . '/inc/template-tags.php';
  237. /**
  238. * Custom functions that act independently of the theme templates.
  239. */
  240. require get_template_directory() . '/inc/extras.php';
  241. /**
  242. * Customizer additions.
  243. */
  244. require get_template_directory() . '/inc/customizer.php';
  245. /**
  246. * Load Jetpack compatibility file.
  247. */
  248. require get_template_directory() . '/inc/jetpack.php';
  249. /**
  250. * Load WooCommerce compatibility file.
  251. */
  252. if ( class_exists( 'WooCommerce' ) ) {
  253. require get_template_directory() . '/inc/woocommerce.php';
  254. }