functions.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /**
  3. * Shoreditch functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Shoreditch
  8. */
  9. if ( ! function_exists( 'shoreditch_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 shoreditch_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 Shoreditch, use a find and replace
  22. * to change 'shoreditch' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'shoreditch', 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. set_post_thumbnail_size( 2000, 1500, true );
  41. // Enable support for custom logo.
  42. add_theme_support( 'custom-logo', array(
  43. 'height' => 480,
  44. 'width' => 480,
  45. 'flex-height' => true,
  46. ) );
  47. // This theme uses wp_nav_menu() in one location.
  48. register_nav_menus( array(
  49. 'primary' => esc_html__( 'Primary', 'shoreditch' ),
  50. ) );
  51. /*
  52. * Switch default core markup for search form, comment form, and comments
  53. * to output valid HTML5.
  54. */
  55. add_theme_support( 'html5', array(
  56. 'search-form',
  57. 'comment-form',
  58. 'comment-list',
  59. 'gallery',
  60. 'caption',
  61. ) );
  62. // Set up the WordPress core custom background feature.
  63. add_theme_support( 'custom-background', apply_filters( 'shoreditch_custom_background_args', array(
  64. 'default-color' => 'ffffff',
  65. 'default-image' => '',
  66. ) ) );
  67. /**
  68. * Add support for Eventbrite.
  69. * See: https://wordpress.org/plugins/eventbrite-api/
  70. */
  71. add_theme_support( 'eventbrite' );
  72. // Add support for responsive embeds.
  73. add_theme_support( 'responsive-embeds' );
  74. // Add support for full and wide align images.
  75. add_theme_support( 'align-wide' );
  76. // Add support for custom color scheme.
  77. add_theme_support( 'editor-color-palette', array(
  78. array(
  79. 'name' => esc_html__( 'Blue', 'shoreditch' ),
  80. 'slug' => 'blue',
  81. 'color' => '#3e69dc',
  82. ),
  83. array(
  84. 'name' => esc_html__( 'Dark Gray', 'shoreditch' ),
  85. 'slug' => 'dark-gray',
  86. 'color' => '#2c313f',
  87. ),
  88. array(
  89. 'name' => esc_html__( 'Medium Gray', 'shoreditch' ),
  90. 'slug' => 'medium-gray',
  91. 'color' => '#73757D',
  92. ),
  93. array(
  94. 'name' => esc_html__( 'Light Gray', 'shoreditch' ),
  95. 'slug' => 'light-gray',
  96. 'color' => '#f3f3f3',
  97. ),
  98. array(
  99. 'name' => esc_html__( 'White', 'shoreditch' ),
  100. 'slug' => 'white',
  101. 'color' => '#fff',
  102. ),
  103. ) );
  104. }
  105. endif;
  106. add_action( 'after_setup_theme', 'shoreditch_setup' );
  107. /**
  108. * Set the content width in pixels, based on the theme's design and stylesheet.
  109. *
  110. * Priority 0 to make it available to lower priority callbacks.
  111. *
  112. * @global int $content_width
  113. */
  114. function shoreditch_content_width() {
  115. $GLOBALS['content_width'] = apply_filters( 'shoreditch_content_width', 900 );
  116. }
  117. add_action( 'after_setup_theme', 'shoreditch_content_width', 0 );
  118. /**
  119. * Register widget area.
  120. *
  121. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  122. */
  123. function shoreditch_widgets_init() {
  124. register_sidebar( array(
  125. 'name' => esc_html__( 'Sidebar', 'shoreditch' ),
  126. 'id' => 'sidebar-1',
  127. 'description' => '',
  128. 'before_widget' => '<section id="%1$s" class="widget widget-small %2$s">',
  129. 'after_widget' => '</section>',
  130. 'before_title' => '<h2 class="widget-title">',
  131. 'after_title' => '</h2>',
  132. ) );
  133. register_sidebar( array(
  134. 'name' => esc_html__( 'Top Footer', 'shoreditch' ),
  135. 'id' => 'sidebar-2',
  136. 'description' => '',
  137. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  138. 'after_widget' => '</section>',
  139. 'before_title' => '<h2 class="widget-title">',
  140. 'after_title' => '</h2>',
  141. ) );
  142. register_sidebar( array(
  143. 'name' => esc_html__( 'Bottom Footer', 'shoreditch' ),
  144. 'id' => 'sidebar-3',
  145. 'description' => '',
  146. 'before_widget' => '<section id="%1$s" class="widget widget-small %2$s">',
  147. 'after_widget' => '</section>',
  148. 'before_title' => '<h2 class="widget-title">',
  149. 'after_title' => '</h2>',
  150. ) );
  151. }
  152. add_action( 'widgets_init', 'shoreditch_widgets_init' );
  153. if ( ! function_exists( 'shoreditch_fonts_url' ) ) :
  154. /**
  155. * Register Google fonts for Shoreditch.
  156. *
  157. * Create your own shoreditch_fonts_url() function to override in a child theme.
  158. *
  159. * @return string Google fonts URL for the theme.
  160. */
  161. function shoreditch_fonts_url() {
  162. $fonts_url = '';
  163. $fonts = array();
  164. $subsets = 'latin,latin-ext';
  165. /* translators: If there are characters in your language that are not supported by Poppins, translate this to 'off'. Do not translate into your own language. */
  166. if ( 'off' !== esc_html_x( 'on', 'Poppins font: on or off', 'shoreditch' ) ) {
  167. $fonts[] = 'Poppins:400,700';
  168. }
  169. /* translators: If there are characters in your language that are not supported by Lato, translate this to 'off'. Do not translate into your own language. */
  170. if ( 'off' !== esc_html_x( 'on', 'Lato font: on or off', 'shoreditch' ) ) {
  171. $fonts[] = 'Lato:400,700,400italic,700italic';
  172. }
  173. /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
  174. if ( 'off' !== esc_html_x( 'on', 'Inconsolata font: on or off', 'shoreditch' ) ) {
  175. $fonts[] = 'Inconsolata:400,700';
  176. }
  177. if ( $fonts ) {
  178. $fonts_url = add_query_arg( array(
  179. 'family' => urlencode( implode( '|', $fonts ) ),
  180. 'subset' => urlencode( $subsets ),
  181. ), 'https://fonts.googleapis.com/css' );
  182. }
  183. return $fonts_url;
  184. }
  185. endif;
  186. /**
  187. * Enqueue scripts and styles.
  188. */
  189. function shoreditch_scripts() {
  190. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  191. wp_enqueue_style( 'shoreditch-fonts', shoreditch_fonts_url(), array(), null );
  192. wp_enqueue_style( 'shoreditch-style', get_stylesheet_uri() );
  193. // Block stylesheets
  194. wp_enqueue_style( 'shoreditch-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'shoreditch-style' ), '20181018' );
  195. wp_enqueue_script( 'shoreditch-back-top', get_template_directory_uri() . '/js/back-top.js', array(), '20120206', true );
  196. wp_enqueue_script( 'shoreditch-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  197. wp_enqueue_script( 'shoreditch-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20151231', true );
  198. if ( get_theme_mod( 'shoreditch_sticky_header' ) ) {
  199. wp_enqueue_script( 'shoreditch-header', get_template_directory_uri() . '/js/header.js', array(), '20130115', true );
  200. }
  201. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  202. wp_enqueue_script( 'comment-reply' );
  203. }
  204. wp_localize_script( 'shoreditch-back-top', 'shoreditchButtonTitle', array(
  205. 'desc' => esc_html__( 'Back to top', 'shoreditch' ),
  206. ) );
  207. wp_localize_script( 'shoreditch-navigation', 'shoreditchScreenReaderText', array(
  208. 'expand' => esc_html__( 'expand child menu', 'shoreditch' ),
  209. 'collapse' => esc_html__( 'collapse child menu', 'shoreditch' ),
  210. ) );
  211. }
  212. add_action( 'wp_enqueue_scripts', 'shoreditch_scripts' );
  213. /**
  214. * Enqueue editor styles for Gutenberg
  215. */
  216. function shoreditch_block_editor_styles() {
  217. // Block styles.
  218. wp_enqueue_style( 'shoreditch-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  219. // Font styles.
  220. wp_enqueue_style( 'shoreditch-fonts', shoreditch_fonts_url(), array(), null );
  221. }
  222. add_action( 'enqueue_block_editor_assets', 'shoreditch_block_editor_styles' );
  223. /**
  224. * Implement the Custom Header feature.
  225. */
  226. require get_template_directory() . '/inc/custom-header.php';
  227. /**
  228. * Custom template tags for this theme.
  229. */
  230. require get_template_directory() . '/inc/template-tags.php';
  231. /**
  232. * Custom functions that act independently of the theme templates.
  233. */
  234. require get_template_directory() . '/inc/extras.php';
  235. /**
  236. * Customizer additions.
  237. */
  238. require get_template_directory() . '/inc/customizer.php';
  239. /**
  240. * Load Jetpack compatibility file.
  241. */
  242. require get_template_directory() . '/inc/jetpack.php';
  243. /**
  244. * Load WooCommerce compatibility file.
  245. */
  246. if ( class_exists( 'WooCommerce' ) ) {
  247. require( get_template_directory() . '/inc/woocommerce.php' );
  248. }