functions.php 9.1 KB

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