functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * Illustratr functions and definitions
  4. *
  5. * @package Illustratr
  6. */
  7. /**
  8. * Set the content width based on the theme's design and stylesheet.
  9. */
  10. if ( ! isset( $content_width ) ) {
  11. $content_width = 840; /* pixels */
  12. }
  13. if ( ! function_exists( 'illustratr_content_width' ) ) :
  14. /**
  15. * Adjust the content width for image post format and single portfolio.
  16. */
  17. function illustratr_content_width() {
  18. global $content_width;
  19. if ( 'image' == get_post_format() || ( is_singular() && 'jetpack-portfolio' == get_post_type() ) ) {
  20. $content_width = 1100;
  21. }
  22. }
  23. endif;
  24. add_action( 'template_redirect', 'illustratr_content_width' );
  25. if ( ! function_exists( 'illustratr_setup' ) ) :
  26. /**
  27. * Sets up theme defaults and registers support for various WordPress features.
  28. *
  29. * Note that this function is hooked into the after_setup_theme hook, which
  30. * runs before the init hook. The init hook is too late for some features, such
  31. * as indicating support for post thumbnails.
  32. */
  33. function illustratr_setup() {
  34. /*
  35. * Make theme available for translation.
  36. * Translations can be filed in the /languages/ directory.
  37. * If you're building a theme based on Illustratr, use a find and replace
  38. * to change 'illustratr' to the name of your theme in all the template files
  39. */
  40. load_theme_textdomain( 'illustratr', get_template_directory() . '/languages' );
  41. // Add default posts and comments RSS feed links to head.
  42. add_theme_support( 'automatic-feed-links' );
  43. /*
  44. * Let WordPress manage the document title.
  45. * By adding theme support, we declare that this theme does not use a
  46. * hard-coded <title> tag in the document head, and expect WordPress to
  47. * provide it for us.
  48. */
  49. add_theme_support( 'title-tag' );
  50. /**
  51. * Editor styles.
  52. */
  53. add_editor_style( 'editor-style.css' );
  54. /**
  55. * Responsive embeds
  56. */
  57. add_theme_support( 'responsive-embeds' );
  58. /**
  59. * Gutenberg wide and full images support
  60. */
  61. add_theme_support( 'align-wide' );
  62. // Add custom colors to Gutenberg
  63. add_theme_support(
  64. 'editor-color-palette', array(
  65. array(
  66. 'name' => esc_html__( 'Black', 'illustratr' ),
  67. 'slug' => 'black',
  68. 'color' => '#24282d',
  69. ),
  70. array(
  71. 'name' => esc_html__( 'Dark Gray', 'illustratr' ),
  72. 'slug' => 'dark-gray',
  73. 'color' => '#464d4d',
  74. ),
  75. array(
  76. 'name' => esc_html__( 'Medium Gray', 'illustratr' ),
  77. 'slug' => 'medium-gray',
  78. 'color' => '#7f8d8c',
  79. ),
  80. array(
  81. 'name' => esc_html__( 'Light Gray', 'illustratr' ),
  82. 'slug' => 'light-gray',
  83. 'color' => '#f1f2f3',
  84. ),
  85. array(
  86. 'name' => esc_html__( 'White', 'illustratr' ),
  87. 'slug' => 'white',
  88. 'color' => '#ffffff',
  89. ),
  90. array(
  91. 'name' => esc_html__( 'Red', 'illustratr' ),
  92. 'slug' => 'red',
  93. 'color' => '#e06d5e',
  94. ),
  95. array(
  96. 'name' => esc_html__( 'Dark Red', 'illustratr' ),
  97. 'slug' => 'dark-red',
  98. 'color' => '#b44738',
  99. )
  100. )
  101. );
  102. /*
  103. * Enable support for Post Thumbnails on posts and pages.
  104. *
  105. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  106. */
  107. add_theme_support( 'post-thumbnails' );
  108. set_post_thumbnail_size( 400, 300, true );
  109. add_image_size( 'illustratr-featured-image', 1100, 500, true );
  110. add_image_size( 'illustratr-portfolio-featured-image', 800, 9999 );
  111. // This theme uses wp_nav_menu() in two locations.
  112. register_nav_menus( array(
  113. 'primary' => __( 'Primary Menu', 'illustratr' ),
  114. 'social' => __( 'Social Menu', 'illustratr' ),
  115. ) );
  116. // Enable support for Post Formats.
  117. add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio' ) );
  118. // Setup the WordPress core custom background feature.
  119. add_theme_support( 'custom-background', apply_filters( 'illustratr_custom_background_args', array(
  120. 'default-color' => '24282d',
  121. 'default-image' => '',
  122. ) ) );
  123. // Enable support for HTML5 markup.
  124. add_theme_support( 'html5', array(
  125. 'comment-list',
  126. 'search-form',
  127. 'comment-form',
  128. 'gallery',
  129. ) );
  130. // Add support for responsive embeds.
  131. add_theme_support( 'responsive-embeds' );
  132. }
  133. endif; // illustratr_setup
  134. add_action( 'after_setup_theme', 'illustratr_setup' );
  135. /**
  136. * Register widgetized area and update sidebar with default widgets.
  137. */
  138. function illustratr_widgets_init() {
  139. register_sidebar( array(
  140. 'name' => __( 'Footer', 'illustratr' ),
  141. 'id' => 'sidebar-1',
  142. 'description' => __( 'Hidden footer area that is revealed by the + button at the bottom of each page', 'illustratr' ),
  143. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  144. 'after_widget' => '</aside>',
  145. 'before_title' => '<h1 class="widget-title">',
  146. 'after_title' => '</h1>',
  147. ) );
  148. }
  149. add_action( 'widgets_init', 'illustratr_widgets_init' );
  150. /**
  151. * Register Source Sans Pro font.
  152. *
  153. * @return string
  154. */
  155. function illustratr_source_sans_pro_font_url() {
  156. $source_sans_pro_font_url = '';
  157. /* translators: If there are characters in your language that are not supported
  158. * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
  159. */
  160. if ( 'off' !== _x( 'on', 'Source Sans Pro font: on or off', 'illustratr' ) ) {
  161. $subsets = 'latin,latin-ext';
  162. /* translators: To add an additional Source Sans Pro character subset specific to your language, translate this to 'vietnamese'. Do not translate into your own language. */
  163. $subset = _x( 'no-subset', 'Source Sans Pro font: add new subset (vietnamese)', 'illustratr' );
  164. if ( 'vietnamese' == $subset ) {
  165. $subsets .= ',vietnamese';
  166. }
  167. $query_args = array(
  168. 'family' => urlencode( 'Source Sans Pro:400,700,900,400italic,700italic,900italic' ),
  169. 'subset' => urlencode( $subsets ),
  170. );
  171. $source_sans_pro_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  172. }
  173. return $source_sans_pro_font_url;
  174. }
  175. /**
  176. * Register PT Serif font.
  177. *
  178. * @return string
  179. */
  180. function illustratr_pt_serif_font_url() {
  181. $pt_serif_font_url = '';
  182. /* translators: If there are characters in your language that are not supported
  183. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  184. */
  185. if ( 'off' !== _x( 'on', 'PT Serif font: on or off', 'illustratr' ) ) {
  186. $subsets = 'latin,latin-ext';
  187. /* translators: To add an additional PT Serif character subset specific to your language, translate this to 'cyrillic'. Do not translate into your own language. */
  188. $subset = _x( 'no-subset', 'PT Serif font: add new subset (cyrillic)', 'illustratr' );
  189. if ( 'cyrillic' == $subset ) {
  190. $subsets .= ',cyrillic-ext,cyrillic';
  191. }
  192. $query_args = array(
  193. 'family' => urlencode( 'PT Serif:400,700,400italic,700italic' ),
  194. 'subset' => urlencode( $subsets ),
  195. );
  196. $pt_serif_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  197. }
  198. return $pt_serif_font_url;
  199. }
  200. /**
  201. * Register Source Code Pro.
  202. *
  203. * @return string
  204. */
  205. function illustratr_source_code_pro_font_url() {
  206. $source_code_pro_font_url = '';
  207. /* translators: If there are characters in your language that are not supported
  208. * by Source Code Pro, translate this to 'off'. Do not translate into your own language.
  209. */
  210. if ( 'off' !== _x( 'on', 'Source Code Pro font: on or off', 'illustratr' ) ) {
  211. $query_args = array(
  212. 'family' => urlencode( 'Source Code Pro' ),
  213. );
  214. $source_code_pro_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  215. }
  216. return $source_code_pro_font_url;
  217. }
  218. /**
  219. * Enqueue scripts and styles.
  220. */
  221. function illustratr_scripts() {
  222. // Gutenberg styles
  223. wp_enqueue_style( 'illustratr-blocks', get_template_directory_uri() . '/blocks.css' );
  224. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  225. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  226. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  227. if ( wp_style_is( 'genericons', 'registered' ) ) {
  228. wp_enqueue_style( 'genericons' );
  229. } else {
  230. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  231. }
  232. wp_enqueue_style( 'illustratr-style', get_stylesheet_uri() );
  233. wp_enqueue_script( 'illustratr-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  234. wp_enqueue_script( 'illustratr-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  235. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  236. wp_enqueue_script( 'comment-reply' );
  237. }
  238. if ( is_active_sidebar( 'sidebar-1' ) ) {
  239. wp_enqueue_script( 'illustratr-sidebar', get_template_directory_uri() . '/js/sidebar.js', array( 'jquery', 'masonry' ), '20140325', true );
  240. }
  241. wp_enqueue_script( 'illustratr-script', get_template_directory_uri() . '/js/illustratr.js', array( 'jquery', 'underscore' ), '20140317', true );
  242. }
  243. add_action( 'wp_enqueue_scripts', 'illustratr_scripts' );
  244. /**
  245. * Gutenberg Editor Styles
  246. */
  247. function apostrophe_2_editor_styles() {
  248. wp_enqueue_style( 'illustratr-editor-block-style', get_template_directory_uri() . '/editor-blocks.css');
  249. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  250. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  251. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  252. }
  253. add_action( 'enqueue_block_editor_assets', 'apostrophe_2_editor_styles' );
  254. /**
  255. * Enqueue Google fonts style to admin screen for custom header display.
  256. *
  257. * @return void
  258. */
  259. function illustratr_admin_fonts() {
  260. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  261. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  262. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  263. }
  264. add_action( 'admin_print_scripts-appearance_page_custom-header', 'illustratr_admin_fonts' );
  265. /**
  266. * Implement the Custom Header feature.
  267. */
  268. require get_template_directory() . '/inc/custom-header.php';
  269. /**
  270. * Custom template tags for this theme.
  271. */
  272. require get_template_directory() . '/inc/template-tags.php';
  273. /**
  274. * Custom functions that act independently of the theme templates.
  275. */
  276. require get_template_directory() . '/inc/extras.php';
  277. /**
  278. * Customizer additions.
  279. */
  280. require get_template_directory() . '/inc/customizer.php';
  281. /**
  282. * Load Jetpack compatibility file.
  283. */
  284. require get_template_directory() . '/inc/jetpack.php';