functions.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * Sketch functions and definitions
  4. *
  5. * @package Sketch
  6. */
  7. /**
  8. * Set the content width based on the theme's design and stylesheet.
  9. */
  10. if ( ! isset( $content_width ) ) {
  11. $content_width = 764; /* pixels */
  12. }
  13. if ( ! function_exists( 'sketch_content_width' ) ) :
  14. function sketch_content_width() {
  15. global $content_width;
  16. if ( is_page_template( 'fullwidth-page.php' ) || ! is_active_sidebar( 'sidebar-1' ) ) {
  17. $content_width = 1091;
  18. }
  19. }
  20. endif;
  21. add_action( 'template_redirect', 'sketch_content_width' );
  22. if ( ! function_exists( 'sketch_setup' ) ) :
  23. /**
  24. * Sets up theme defaults and registers support for various WordPress features.
  25. *
  26. * Note that this function is hooked into the after_setup_theme hook, which
  27. * runs before the init hook. The init hook is too late for some features, such
  28. * as indicating support for post thumbnails.
  29. */
  30. function sketch_setup() {
  31. /*
  32. * Make theme available for translation.
  33. * Translations can be filed in the /languages/ directory.
  34. * If you're building a theme based on Sketch, use a find and replace
  35. * to change 'sketch' to the name of your theme in all the template files
  36. */
  37. load_theme_textdomain( 'sketch', get_template_directory() . '/languages' );
  38. // Add default posts and comments RSS feed links to head.
  39. add_theme_support( 'automatic-feed-links' );
  40. /*
  41. * Let WordPress manage the document title.
  42. * By adding theme support, we declare that this theme does not use a
  43. * hard-coded <title> tag in the document head, and expect WordPress to
  44. * provide it for us.
  45. */
  46. add_theme_support( 'title-tag' );
  47. /*
  48. * Enable support for Post Thumbnails on posts and pages.
  49. *
  50. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  51. */
  52. add_theme_support( 'post-thumbnails' );
  53. add_image_size( 'sketch-landscape', '800', '600', true );
  54. add_image_size( 'sketch-portrait', '800', '1067', true );
  55. add_image_size( 'sketch-square', '800', '800', true );
  56. add_image_size( 'sketch-featured', '1092', '400', true );
  57. add_image_size( 'sketch-site-logo', '300', '300' );
  58. // This theme uses wp_nav_menu() in one location.
  59. register_nav_menus(
  60. array(
  61. 'primary' => __( 'Primary Menu', 'sketch' ),
  62. 'social' => __( 'Social Links', 'sketch' ),
  63. )
  64. );
  65. /*
  66. * Switch default core markup for search form, comment form, and comments
  67. * to output valid HTML5.
  68. */
  69. add_theme_support(
  70. 'html5',
  71. array(
  72. 'search-form',
  73. 'comment-form',
  74. 'comment-list',
  75. 'gallery',
  76. 'caption',
  77. )
  78. );
  79. /*
  80. * Enable support for Post Formats.
  81. * See http://codex.wordpress.org/Post_Formats
  82. */
  83. add_theme_support(
  84. 'post-formats',
  85. array(
  86. 'aside',
  87. 'image',
  88. 'video',
  89. 'quote',
  90. 'link',
  91. )
  92. );
  93. // Set up the WordPress core custom background feature.
  94. add_theme_support(
  95. 'custom-background',
  96. apply_filters(
  97. 'sketch_custom_background_args',
  98. array(
  99. 'default-color' => 'eeeeee',
  100. 'default-image' => '',
  101. )
  102. )
  103. );
  104. /**
  105. * Add support for Eventbrite.
  106. * See: https://wordpress.org/plugins/eventbrite-api/
  107. */
  108. add_theme_support( 'eventbrite' );
  109. // Add support for responsive embeds.
  110. add_theme_support( 'responsive-embeds' );
  111. // Add support for custom color scheme.
  112. add_theme_support(
  113. 'editor-color-palette',
  114. array(
  115. array(
  116. 'name' => esc_html__( 'Orange', 'sketch' ),
  117. 'slug' => 'orange',
  118. 'color' => '#f68060',
  119. ),
  120. array(
  121. 'name' => esc_html__( 'Dark Gray', 'sketch' ),
  122. 'slug' => 'dark-gray',
  123. 'color' => '#333',
  124. ),
  125. array(
  126. 'name' => esc_html__( 'Medium Gray', 'sketch' ),
  127. 'slug' => 'medium-gray',
  128. 'color' => '#999',
  129. ),
  130. array(
  131. 'name' => esc_html__( 'Light Gray', 'sketch' ),
  132. 'slug' => 'light-gray',
  133. 'color' => '#eee',
  134. ),
  135. array(
  136. 'name' => esc_html__( 'White', 'sketch' ),
  137. 'slug' => 'white',
  138. 'color' => '#fff',
  139. ),
  140. )
  141. );
  142. }
  143. endif; // sketch_setup
  144. add_action( 'after_setup_theme', 'sketch_setup' );
  145. /**
  146. * Register widget area.
  147. *
  148. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  149. */
  150. function sketch_widgets_init() {
  151. register_sidebar(
  152. array(
  153. 'name' => __( 'Sidebar', 'sketch' ),
  154. 'id' => 'sidebar-1',
  155. 'description' => '',
  156. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  157. 'after_widget' => '</aside>',
  158. 'before_title' => '<h1 class="widget-title">',
  159. 'after_title' => '</h1>',
  160. )
  161. );
  162. }
  163. add_action( 'widgets_init', 'sketch_widgets_init' );
  164. /**
  165. * Enqueue scripts and styles.
  166. */
  167. function sketch_scripts() {
  168. wp_enqueue_style( 'sketch-style', get_stylesheet_uri() );
  169. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  170. // Block stylesheets
  171. wp_enqueue_style( 'sketch-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'sketch-style' ), '20181018' );
  172. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  173. if ( sketch_has_featured_posts( 2 ) && is_page_template( 'portfolio-page.php' ) ) {
  174. wp_enqueue_script( 'sketch-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '20150811', true );
  175. wp_enqueue_script( 'sketch-script', get_template_directory_uri() . '/js/sketch.js', array( 'jquery' ), '20140530', true );
  176. }
  177. wp_enqueue_script( 'sketch-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  178. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  179. wp_enqueue_script( 'sketch-portfolio', get_template_directory_uri() . '/js/portfolio.js', array( 'jquery' ), '20150708', true );
  180. }
  181. wp_enqueue_script( 'sketch-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  182. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  183. wp_enqueue_script( 'comment-reply' );
  184. }
  185. }
  186. add_action( 'wp_enqueue_scripts', 'sketch_scripts' );
  187. /**
  188. * Enqueue editor styles for Gutenberg
  189. */
  190. function sketch_block_editor_styles() {
  191. // Block styles.
  192. wp_enqueue_style( 'sketch-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  193. // Font styles.
  194. wp_enqueue_style( 'sketch-fonts', sketch_fonts_url(), array(), null );
  195. }
  196. add_action( 'enqueue_block_editor_assets', 'sketch_block_editor_styles' );
  197. /**
  198. * Register Google Fonts
  199. */
  200. function sketch_fonts_url() {
  201. $fonts_url = '';
  202. /* Translators: If there are characters in your language that are not
  203. * supported by Lato, translate this to 'off'. Do not translate
  204. * into your own language.
  205. */
  206. $lato = _x( 'on', 'Lato font: on or off', 'sketch' );
  207. if ( 'off' !== $lato ) {
  208. $font_families = array();
  209. $font_families[] = 'Lato:300,400,700,300italic,400italic,700italic';
  210. /**
  211. * A filter to enable child themes to add/change/omit font families.
  212. *
  213. * @param array $font_families An array of font families to be imploded for the Google Font API
  214. */
  215. $font_families = apply_filters( 'included_google_font_families', $font_families );
  216. $query_args = array(
  217. 'family' => urlencode( implode( '|', $font_families ) ),
  218. 'subset' => urlencode( 'latin,latin-ext' ),
  219. );
  220. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  221. }
  222. return $fonts_url;
  223. }
  224. /**
  225. * Enqueue Google Fonts for custom headers
  226. */
  227. function sketch_admin_scripts() {
  228. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  229. }
  230. add_action( 'admin_print_styles-appearance_page_custom-header', 'sketch_admin_scripts' );
  231. /**
  232. * Determine and return the appropriate thumbnail size
  233. */
  234. function sketch_post_thumbnail_class() {
  235. if ( 'portrait' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  236. $thumbsize = 'sketch-portrait';
  237. elseif ( 'square' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  238. $thumbsize = 'sketch-square';
  239. else :
  240. $thumbsize = 'sketch-landscape';
  241. endif;
  242. if ( ! has_post_thumbnail() ) {
  243. $thumbsize .= ' no-thumbnail';
  244. }
  245. return $thumbsize;
  246. }
  247. /**
  248. * Use a pipe for Eventbrite meta separators.
  249. */
  250. function sketch_eventbrite_meta_separator() {
  251. return '<span class="sep"> | </span>';
  252. }
  253. add_filter( 'eventbrite_meta_separator', 'sketch_eventbrite_meta_separator' );
  254. /**
  255. * Implement the Custom Header feature.
  256. */
  257. require get_template_directory() . '/inc/custom-header.php';
  258. /**
  259. * Custom template tags for this theme.
  260. */
  261. require get_template_directory() . '/inc/template-tags.php';
  262. /**
  263. * Custom functions that act independently of the theme templates.
  264. */
  265. require get_template_directory() . '/inc/extras.php';
  266. /**
  267. * Customizer additions.
  268. */
  269. require get_template_directory() . '/inc/customizer.php';
  270. /**
  271. * Load Jetpack compatibility file.
  272. */
  273. require get_template_directory() . '/inc/jetpack.php';