functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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',
  65. array(
  66. array(
  67. 'name' => esc_html__( 'Black', 'illustratr' ),
  68. 'slug' => 'black',
  69. 'color' => '#24282d',
  70. ),
  71. array(
  72. 'name' => esc_html__( 'Dark Gray', 'illustratr' ),
  73. 'slug' => 'dark-gray',
  74. 'color' => '#464d4d',
  75. ),
  76. array(
  77. 'name' => esc_html__( 'Medium Gray', 'illustratr' ),
  78. 'slug' => 'medium-gray',
  79. 'color' => '#7f8d8c',
  80. ),
  81. array(
  82. 'name' => esc_html__( 'Light Gray', 'illustratr' ),
  83. 'slug' => 'light-gray',
  84. 'color' => '#f1f2f3',
  85. ),
  86. array(
  87. 'name' => esc_html__( 'White', 'illustratr' ),
  88. 'slug' => 'white',
  89. 'color' => '#ffffff',
  90. ),
  91. array(
  92. 'name' => esc_html__( 'Red', 'illustratr' ),
  93. 'slug' => 'red',
  94. 'color' => '#e06d5e',
  95. ),
  96. array(
  97. 'name' => esc_html__( 'Dark Red', 'illustratr' ),
  98. 'slug' => 'dark-red',
  99. 'color' => '#b44738',
  100. ),
  101. )
  102. );
  103. /*
  104. * Enable support for Post Thumbnails on posts and pages.
  105. *
  106. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  107. */
  108. add_theme_support( 'post-thumbnails' );
  109. set_post_thumbnail_size( 400, 300, true );
  110. add_image_size( 'illustratr-featured-image', 1100, 500, true );
  111. add_image_size( 'illustratr-portfolio-featured-image', 800, 9999 );
  112. // This theme uses wp_nav_menu() in two locations.
  113. register_nav_menus(
  114. array(
  115. 'primary' => __( 'Primary Menu', 'illustratr' ),
  116. 'social' => __( 'Social Menu', 'illustratr' ),
  117. )
  118. );
  119. // Enable support for Post Formats.
  120. add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio' ) );
  121. // Setup the WordPress core custom background feature.
  122. add_theme_support(
  123. 'custom-background',
  124. apply_filters(
  125. 'illustratr_custom_background_args',
  126. array(
  127. 'default-color' => '24282d',
  128. 'default-image' => '',
  129. )
  130. )
  131. );
  132. // Enable support for HTML5 markup.
  133. add_theme_support(
  134. 'html5',
  135. array(
  136. 'comment-list',
  137. 'search-form',
  138. 'comment-form',
  139. 'gallery',
  140. )
  141. );
  142. // Add support for responsive embeds.
  143. add_theme_support( 'responsive-embeds' );
  144. }
  145. endif; // illustratr_setup
  146. add_action( 'after_setup_theme', 'illustratr_setup' );
  147. /**
  148. * Register widgetized area and update sidebar with default widgets.
  149. */
  150. function illustratr_widgets_init() {
  151. register_sidebar(
  152. array(
  153. 'name' => __( 'Footer', 'illustratr' ),
  154. 'id' => 'sidebar-1',
  155. 'description' => __( 'Hidden footer area that is revealed by the + button at the bottom of each page', 'illustratr' ),
  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', 'illustratr_widgets_init' );
  164. /**
  165. * Register Source Sans Pro font.
  166. *
  167. * @return string
  168. */
  169. function illustratr_source_sans_pro_font_url() {
  170. $source_sans_pro_font_url = '';
  171. /* translators: If there are characters in your language that are not supported
  172. * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
  173. */
  174. if ( 'off' !== _x( 'on', 'Source Sans Pro font: on or off', 'illustratr' ) ) {
  175. $subsets = 'latin,latin-ext';
  176. /* 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. */
  177. $subset = _x( 'no-subset', 'Source Sans Pro font: add new subset (vietnamese)', 'illustratr' );
  178. if ( 'vietnamese' == $subset ) {
  179. $subsets .= ',vietnamese';
  180. }
  181. $query_args = array(
  182. 'family' => urlencode( 'Source Sans Pro:400,700,900,400italic,700italic,900italic' ),
  183. 'subset' => urlencode( $subsets ),
  184. );
  185. $source_sans_pro_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  186. }
  187. return $source_sans_pro_font_url;
  188. }
  189. /**
  190. * Register PT Serif font.
  191. *
  192. * @return string
  193. */
  194. function illustratr_pt_serif_font_url() {
  195. $pt_serif_font_url = '';
  196. /* translators: If there are characters in your language that are not supported
  197. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  198. */
  199. if ( 'off' !== _x( 'on', 'PT Serif font: on or off', 'illustratr' ) ) {
  200. $subsets = 'latin,latin-ext';
  201. /* translators: To add an additional PT Serif character subset specific to your language, translate this to 'cyrillic'. Do not translate into your own language. */
  202. $subset = _x( 'no-subset', 'PT Serif font: add new subset (cyrillic)', 'illustratr' );
  203. if ( 'cyrillic' == $subset ) {
  204. $subsets .= ',cyrillic-ext,cyrillic';
  205. }
  206. $query_args = array(
  207. 'family' => urlencode( 'PT Serif:400,700,400italic,700italic' ),
  208. 'subset' => urlencode( $subsets ),
  209. );
  210. $pt_serif_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  211. }
  212. return $pt_serif_font_url;
  213. }
  214. /**
  215. * Register Source Code Pro.
  216. *
  217. * @return string
  218. */
  219. function illustratr_source_code_pro_font_url() {
  220. $source_code_pro_font_url = '';
  221. /* translators: If there are characters in your language that are not supported
  222. * by Source Code Pro, translate this to 'off'. Do not translate into your own language.
  223. */
  224. if ( 'off' !== _x( 'on', 'Source Code Pro font: on or off', 'illustratr' ) ) {
  225. $query_args = array(
  226. 'family' => urlencode( 'Source Code Pro' ),
  227. );
  228. $source_code_pro_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  229. }
  230. return $source_code_pro_font_url;
  231. }
  232. /**
  233. * Enqueue scripts and styles.
  234. */
  235. function illustratr_scripts() {
  236. // Gutenberg styles
  237. wp_enqueue_style( 'illustratr-blocks', get_template_directory_uri() . '/blocks.css' );
  238. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  239. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  240. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  241. if ( wp_style_is( 'genericons', 'registered' ) ) {
  242. wp_enqueue_style( 'genericons' );
  243. } else {
  244. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  245. }
  246. wp_enqueue_style( 'illustratr-style', get_stylesheet_uri() );
  247. wp_enqueue_script( 'illustratr-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  248. wp_enqueue_script( 'illustratr-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  249. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  250. wp_enqueue_script( 'comment-reply' );
  251. }
  252. if ( is_active_sidebar( 'sidebar-1' ) ) {
  253. wp_enqueue_script( 'illustratr-sidebar', get_template_directory_uri() . '/js/sidebar.js', array( 'jquery', 'masonry' ), '20140325', true );
  254. }
  255. wp_enqueue_script( 'illustratr-script', get_template_directory_uri() . '/js/illustratr.js', array( 'jquery', 'underscore' ), '20140317', true );
  256. }
  257. add_action( 'wp_enqueue_scripts', 'illustratr_scripts' );
  258. /**
  259. * Gutenberg Editor Styles
  260. */
  261. function apostrophe_2_editor_styles() {
  262. wp_enqueue_style( 'illustratr-editor-block-style', get_template_directory_uri() . '/editor-blocks.css' );
  263. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  264. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  265. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  266. }
  267. add_action( 'enqueue_block_editor_assets', 'apostrophe_2_editor_styles' );
  268. /**
  269. * Enqueue Google fonts style to admin screen for custom header display.
  270. *
  271. * @return void
  272. */
  273. function illustratr_admin_fonts() {
  274. wp_enqueue_style( 'illustratr-source-sans-pro', illustratr_source_sans_pro_font_url(), array(), null );
  275. wp_enqueue_style( 'illustratr-pt-serif', illustratr_pt_serif_font_url(), array(), null );
  276. wp_enqueue_style( 'illustratr-source-code-pro', illustratr_source_code_pro_font_url(), array(), null );
  277. }
  278. add_action( 'admin_print_scripts-appearance_page_custom-header', 'illustratr_admin_fonts' );
  279. /**
  280. * Implement the Custom Header feature.
  281. */
  282. require get_template_directory() . '/inc/custom-header.php';
  283. /**
  284. * Custom template tags for this theme.
  285. */
  286. require get_template_directory() . '/inc/template-tags.php';
  287. /**
  288. * Custom functions that act independently of the theme templates.
  289. */
  290. require get_template_directory() . '/inc/extras.php';
  291. /**
  292. * Customizer additions.
  293. */
  294. require get_template_directory() . '/inc/customizer.php';
  295. /**
  296. * Load Jetpack compatibility file.
  297. */
  298. require get_template_directory() . '/inc/jetpack.php';