functions.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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( array(
  60. 'primary' => __( 'Primary Menu', 'sketch' ),
  61. 'social' => __( 'Social Links', 'sketch' ),
  62. ) );
  63. /*
  64. * Switch default core markup for search form, comment form, and comments
  65. * to output valid HTML5.
  66. */
  67. add_theme_support( 'html5', array(
  68. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  69. ) );
  70. /*
  71. * Enable support for Post Formats.
  72. * See http://codex.wordpress.org/Post_Formats
  73. */
  74. add_theme_support( 'post-formats', array(
  75. 'aside', 'image', 'video', 'quote', 'link'
  76. ) );
  77. // Set up the WordPress core custom background feature.
  78. add_theme_support( 'custom-background', apply_filters( 'sketch_custom_background_args', array(
  79. 'default-color' => 'eeeeee',
  80. 'default-image' => '',
  81. ) ) );
  82. /**
  83. * Add support for Eventbrite.
  84. * See: https://wordpress.org/plugins/eventbrite-api/
  85. */
  86. add_theme_support( 'eventbrite' );
  87. // Add support for responsive embeds.
  88. add_theme_support( 'responsive-embeds' );
  89. // Add support for custom color scheme.
  90. add_theme_support( 'editor-color-palette', array(
  91. array(
  92. 'name' => esc_html__( 'Orange', 'sketch' ),
  93. 'slug' => 'orange',
  94. 'color' => '#f68060',
  95. ),
  96. array(
  97. 'name' => esc_html__( 'Dark Gray', 'sketch' ),
  98. 'slug' => 'dark-gray',
  99. 'color' => '#333',
  100. ),
  101. array(
  102. 'name' => esc_html__( 'Medium Gray', 'sketch' ),
  103. 'slug' => 'medium-gray',
  104. 'color' => '#999',
  105. ),
  106. array(
  107. 'name' => esc_html__( 'Light Gray', 'sketch' ),
  108. 'slug' => 'light-gray',
  109. 'color' => '#eee',
  110. ),
  111. array(
  112. 'name' => esc_html__( 'White', 'sketch' ),
  113. 'slug' => 'white',
  114. 'color' => '#fff',
  115. ),
  116. ) );
  117. }
  118. endif; // sketch_setup
  119. add_action( 'after_setup_theme', 'sketch_setup' );
  120. /**
  121. * Register widget area.
  122. *
  123. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  124. */
  125. function sketch_widgets_init() {
  126. register_sidebar( array(
  127. 'name' => __( 'Sidebar', 'sketch' ),
  128. 'id' => 'sidebar-1',
  129. 'description' => '',
  130. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  131. 'after_widget' => '</aside>',
  132. 'before_title' => '<h1 class="widget-title">',
  133. 'after_title' => '</h1>',
  134. ) );
  135. }
  136. add_action( 'widgets_init', 'sketch_widgets_init' );
  137. /**
  138. * Enqueue scripts and styles.
  139. */
  140. function sketch_scripts() {
  141. wp_enqueue_style( 'sketch-style', get_stylesheet_uri() );
  142. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  143. // Block stylesheets
  144. wp_enqueue_style( 'sketch-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'sketch-style' ), '20181018' );
  145. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  146. if ( sketch_has_featured_posts( 2 ) && is_page_template( 'portfolio-page.php' ) ) {
  147. wp_enqueue_script( 'sketch-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '20150811', true );
  148. wp_enqueue_script( 'sketch-script', get_template_directory_uri() . '/js/sketch.js', array( 'jquery' ), '20140530', true );
  149. }
  150. wp_enqueue_script( 'sketch-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  151. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  152. wp_enqueue_script( 'sketch-portfolio', get_template_directory_uri() . '/js/portfolio.js', array( 'jquery' ), '20150708', true );
  153. }
  154. wp_enqueue_script( 'sketch-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  155. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  156. wp_enqueue_script( 'comment-reply' );
  157. }
  158. }
  159. add_action( 'wp_enqueue_scripts', 'sketch_scripts' );
  160. /**
  161. * Enqueue editor styles for Gutenberg
  162. */
  163. function sketch_block_editor_styles() {
  164. // Block styles.
  165. wp_enqueue_style( 'sketch-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
  166. // Font styles.
  167. wp_enqueue_style( 'sketch-fonts', sketch_fonts_url(), array(), null );
  168. }
  169. add_action( 'enqueue_block_editor_assets', 'sketch_block_editor_styles' );
  170. /**
  171. * Register Google Fonts
  172. */
  173. function sketch_fonts_url() {
  174. $fonts_url = '';
  175. /* Translators: If there are characters in your language that are not
  176. * supported by Lato, translate this to 'off'. Do not translate
  177. * into your own language.
  178. */
  179. $lato = _x( 'on', 'Lato font: on or off', 'sketch' );
  180. if ( 'off' !== $lato ) {
  181. $font_families = array();
  182. $font_families[] = 'Lato:300,400,700,300italic,400italic,700italic';
  183. $query_args = array(
  184. 'family' => urlencode( implode( '|', $font_families ) ),
  185. 'subset' => urlencode( 'latin,latin-ext' ),
  186. );
  187. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  188. }
  189. return $fonts_url;
  190. }
  191. /**
  192. * Enqueue Google Fonts for custom headers
  193. */
  194. function sketch_admin_scripts() {
  195. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  196. }
  197. add_action( 'admin_print_styles-appearance_page_custom-header', 'sketch_admin_scripts' );
  198. /**
  199. * Determine and return the appropriate thumbnail size
  200. */
  201. function sketch_post_thumbnail_class() {
  202. if ( 'portrait' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  203. $thumbsize = 'sketch-portrait';
  204. elseif ( 'square' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  205. $thumbsize = 'sketch-square';
  206. else :
  207. $thumbsize = 'sketch-landscape';
  208. endif;
  209. if ( ! has_post_thumbnail() )
  210. $thumbsize .= ' no-thumbnail';
  211. return $thumbsize;
  212. }
  213. /**
  214. * Use a pipe for Eventbrite meta separators.
  215. */
  216. function sketch_eventbrite_meta_separator() {
  217. return '<span class="sep"> | </span>';
  218. }
  219. add_filter( 'eventbrite_meta_separator', 'sketch_eventbrite_meta_separator' );
  220. /**
  221. * Implement the Custom Header feature.
  222. */
  223. require get_template_directory() . '/inc/custom-header.php';
  224. /**
  225. * Custom template tags for this theme.
  226. */
  227. require get_template_directory() . '/inc/template-tags.php';
  228. /**
  229. * Custom functions that act independently of the theme templates.
  230. */
  231. require get_template_directory() . '/inc/extras.php';
  232. /**
  233. * Customizer additions.
  234. */
  235. require get_template_directory() . '/inc/customizer.php';
  236. /**
  237. * Load Jetpack compatibility file.
  238. */
  239. require get_template_directory() . '/inc/jetpack.php';