functions.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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( array(
  41. 'menu-1' => esc_html__( 'Header', 'button-2' ),
  42. ) );
  43. /*
  44. * Switch default core markup for search form, comment form, and comments
  45. * to output valid HTML5.
  46. */
  47. add_theme_support( 'html5', array(
  48. 'search-form',
  49. 'comment-form',
  50. 'comment-list',
  51. 'gallery',
  52. 'caption',
  53. ) );
  54. // Enable support for custom logo.
  55. add_theme_support( 'custom-logo', array(
  56. 'height' => 300,
  57. 'width' => 1200,
  58. 'flex-height' => true,
  59. 'flex-width' => true
  60. ) );
  61. // Add theme support for selective refresh for widgets.
  62. add_theme_support( 'customize-selective-refresh-widgets' );
  63. // Set up the WordPress core custom background feature.
  64. add_theme_support( 'custom-background', apply_filters( 'button_2_custom_background_args', array(
  65. 'default-color' => 'f8f8f8',
  66. /*
  67. * We're using a unique filename for the background image
  68. * to avoid users uploading a file with the same filename
  69. * and avoiding conflict with the `user-background` body_class
  70. * in inc/extras.php and assets/js/customizer.js
  71. */
  72. 'default-image' => esc_url( get_template_directory_uri() ) . '/img/buttonbg20170303.png',
  73. ) ) );
  74. }
  75. endif; // button_2_setup
  76. add_action( 'after_setup_theme', 'button_2_setup' );
  77. /**
  78. * Set the content width in pixels, based on the theme's design and stylesheet.
  79. *
  80. * Priority 0 to make it available to lower priority callbacks.
  81. *
  82. * @global int $content_width
  83. */
  84. function button_2_content_width() {
  85. $GLOBALS['content_width'] = apply_filters( 'button_2_content_width', 663 );
  86. }
  87. add_action( 'after_setup_theme', 'button_2_content_width', 0 );
  88. /**
  89. * Adjust content width for full-width page template
  90. */
  91. function button_2_adjusted_content_width() {
  92. global $content_width;
  93. if ( is_page_template( 'templates/full-width-page.php' ) || ! is_active_sidebar( 'sidebar-1' ) ) {
  94. $content_width = 982;
  95. }
  96. }
  97. add_action( 'template_redirect', 'button_2_adjusted_content_width', 0 );
  98. /**
  99. * Register widget area.
  100. *
  101. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  102. */
  103. function button_2_widgets_init() {
  104. register_sidebar( array(
  105. 'name' => esc_html__( 'Sidebar', 'button-2' ),
  106. 'id' => 'sidebar-1',
  107. 'description' => '',
  108. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  109. 'after_widget' => '</aside>',
  110. 'before_title' => '<h1 class="widget-title">',
  111. 'after_title' => '</h1>',
  112. ) );
  113. register_sidebar( array(
  114. 'name' => esc_html__( 'Footer 1', 'button-2' ),
  115. 'id' => 'sidebar-2',
  116. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  117. 'after_widget' => '</aside>',
  118. 'before_title' => '<h1 class="widget-title">',
  119. 'after_title' => '</h1>',
  120. ) );
  121. register_sidebar( array(
  122. 'name' => esc_html__( 'Footer 2', 'button-2' ),
  123. 'id' => 'sidebar-3',
  124. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  125. 'after_widget' => '</aside>',
  126. 'before_title' => '<h1 class="widget-title">',
  127. 'after_title' => '</h1>',
  128. ) );
  129. register_sidebar( array(
  130. 'name' => esc_html__( 'Footer 3', 'button-2' ),
  131. 'id' => 'sidebar-4',
  132. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  133. 'after_widget' => '</aside>',
  134. 'before_title' => '<h1 class="widget-title">',
  135. 'after_title' => '</h1>',
  136. ) );
  137. }
  138. add_action( 'widgets_init', 'button_2_widgets_init' );
  139. /**
  140. * Enqueue scripts and styles.
  141. */
  142. function button_2_scripts() {
  143. wp_enqueue_style( 'button-2-style', get_stylesheet_uri() );
  144. wp_enqueue_style( 'button-2-fonts', button_2_fonts_url(), array(), null );
  145. wp_enqueue_script( 'button-2-scripts', get_template_directory_uri() . '/assets/js/main.js', array(), '20170303', true );
  146. wp_enqueue_script( 'button-2-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  147. wp_enqueue_script( 'button-2-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  148. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  149. wp_enqueue_script( 'comment-reply' );
  150. }
  151. }
  152. add_action( 'wp_enqueue_scripts', 'button_2_scripts' );
  153. /**
  154. * Register Google Fonts
  155. */
  156. function button_2_fonts_url() {
  157. $fonts_url = '';
  158. /* Translators: If there are characters in your language that are not
  159. * supported by Lato, translate this to 'off'. Do not translate
  160. * into your own language.
  161. */
  162. $lato = esc_html_x( 'on', 'Lato font: on or off', 'button-2' );
  163. /* Translators: If there are characters in your language that are not
  164. * supported by Lora, translate this to 'off'. Do not translate
  165. * into your own language.
  166. */
  167. $lora = esc_html_x( 'on', 'Lora font: on or off', 'button-2' );
  168. if ( 'off' !== $lato || 'off' !== $lora ) {
  169. $font_families = array();
  170. if ( 'off' !== $lato ) {
  171. $font_families[] = 'Lato:400,300,300italic,400italic,700,700italic';
  172. }
  173. if ( 'off' !== $lora ) {
  174. $font_families[] = 'Lora:400italic,700italic';
  175. }
  176. $query_args = array(
  177. 'family' => urlencode( implode( '|', $font_families ) ),
  178. 'subset' => urlencode( 'latin,latin-ext' ),
  179. );
  180. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  181. }
  182. return $fonts_url;
  183. }
  184. /**
  185. * Implement the Custom Header feature.
  186. */
  187. require get_template_directory() . '/inc/custom-header.php';
  188. /**
  189. * Custom template tags for this theme.
  190. */
  191. require get_template_directory() . '/inc/template-tags.php';
  192. /**
  193. * Custom functions that act independently of the theme templates.
  194. */
  195. require get_template_directory() . '/inc/extras.php';
  196. /**
  197. * Customizer additions.
  198. */
  199. require get_template_directory() . '/inc/customizer.php';
  200. /**
  201. * Load Jetpack compatibility file.
  202. */
  203. require get_template_directory() . '/inc/jetpack.php';
  204. /**
  205. * Load WooCommerce compatibility file.
  206. */
  207. if ( class_exists( 'WooCommerce' ) ) {
  208. require get_template_directory() . '/inc/woocommerce.php';
  209. }