functions.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /**
  3. * Penscratch 2 functions and definitions
  4. *
  5. * @package Penscratch 2
  6. */
  7. if ( ! function_exists( 'penscratch_2_setup' ) ) :
  8. /**
  9. * Sets up theme defaults and registers support for various WordPress features.
  10. *
  11. * Note that this function is hooked into the after_setup_theme hook, which
  12. * runs before the init hook. The init hook is too late for some features, such
  13. * as indicating support for post thumbnails.
  14. */
  15. function penscratch_2_setup() {
  16. /*
  17. * Make theme available for translation.
  18. * Translations can be filed in the /languages/ directory.
  19. * If you're building a theme based on Penscratch 2, use a find and replace
  20. * to change 'penscratch-2' to the name of your theme in all the template files
  21. */
  22. load_theme_textdomain( 'penscratch-2', get_template_directory() . '/languages' );
  23. // Add default posts and comments RSS feed links to head.
  24. add_theme_support( 'automatic-feed-links' );
  25. /*
  26. * Let WordPress manage the document title.
  27. * By adding theme support, we declare that this theme does not use a
  28. * hard-coded <title> tag in the document head, and expect WordPress to
  29. * provide it for us.
  30. */
  31. add_theme_support( 'title-tag' );
  32. /*
  33. * Enable support for Post Thumbnails on posts and pages.
  34. *
  35. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  36. */
  37. add_theme_support( 'post-thumbnails' );
  38. add_image_size( 'penscratch-2-featured', '656', '300', true );
  39. // This theme uses wp_nav_menu() in one location.
  40. register_nav_menus(
  41. array(
  42. 'menu-1' => esc_html__( 'Header', 'penscratch-2' ),
  43. )
  44. );
  45. add_editor_style( array( 'editor-style.css', penscratch_2_fonts_url() ) );
  46. /*
  47. * Switch default core markup for search form, comment form, and comments
  48. * to output valid HTML5.
  49. */
  50. add_theme_support(
  51. 'html5',
  52. array(
  53. 'search-form',
  54. 'comment-form',
  55. 'comment-list',
  56. 'gallery',
  57. 'caption',
  58. )
  59. );
  60. // Enable support for custom logo.
  61. add_theme_support(
  62. 'custom-logo',
  63. array(
  64. 'height' => 400,
  65. 'width' => 1200,
  66. 'flex-height' => true,
  67. 'flex-width' => true,
  68. )
  69. );
  70. // Add theme support for selective refresh for widgets.
  71. add_theme_support( 'customize-selective-refresh-widgets' );
  72. // Setup the WordPress core custom background feature.
  73. add_theme_support(
  74. 'custom-background',
  75. apply_filters(
  76. 'penscratch_2_custom_background_args',
  77. array(
  78. 'default-color' => 'eeeeee',
  79. 'default-image' => '',
  80. )
  81. )
  82. );
  83. // Add support for responsive embeds.
  84. add_theme_support( 'responsive-embeds' );
  85. // Add custom colors to Gutenberg
  86. add_theme_support(
  87. 'editor-color-palette',
  88. array(
  89. array(
  90. 'name' => esc_html__( 'Dark Green', 'penscratch-2' ),
  91. 'slug' => 'dark-green',
  92. 'color' => '#1c7c7c',
  93. ),
  94. array(
  95. 'name' => esc_html__( 'Dark Gray', 'penscratch-2' ),
  96. 'slug' => 'dark-gray',
  97. 'color' => '#666',
  98. ),
  99. array(
  100. 'name' => esc_html__( 'Medium Gray', 'penscratch-2' ),
  101. 'slug' => 'medium-gray',
  102. 'color' => '#999',
  103. ),
  104. array(
  105. 'name' => esc_html__( 'Light Gray', 'penscratch-2' ),
  106. 'slug' => 'light-gray',
  107. 'color' => '#eee',
  108. ),
  109. array(
  110. 'name' => esc_html__( 'White', 'penscratch-2' ),
  111. 'slug' => 'white',
  112. 'color' => '#fff',
  113. ),
  114. )
  115. );
  116. add_theme_support( 'editor-styles' );
  117. add_editor_style(
  118. array(
  119. 'style.css',
  120. '/css/blocks.css',
  121. '/css/editor-blocks.css',
  122. penscratch_2_fonts_url(),
  123. )
  124. );
  125. }
  126. endif; // penscratch_2_setup
  127. add_action( 'after_setup_theme', 'penscratch_2_setup' );
  128. /**
  129. * Set the content width in pixels, based on the theme's design and stylesheet.
  130. *
  131. * Priority 0 to make it available to lower priority callbacks.
  132. *
  133. * @global int $content_width
  134. */
  135. function penscratch_2_content_width() {
  136. $GLOBALS['content_width'] = apply_filters( 'penscratch_2_content_width', 656 );
  137. }
  138. add_action( 'after_setup_theme', 'penscratch_2_content_width', 0 );
  139. function penscratch_2_adjust_content_width() {
  140. global $content_width;
  141. if ( is_page_template( 'templates/full-width-page.php' ) ) {
  142. $content_width = 937;
  143. }
  144. }
  145. add_action( 'template_redirect', 'penscratch_2_adjust_content_width' );
  146. /**
  147. * Register widget area.
  148. *
  149. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  150. */
  151. function penscratch_2_widgets_init() {
  152. register_sidebar(
  153. array(
  154. 'name' => esc_html__( 'Sidebar', 'penscratch-2' ),
  155. 'id' => 'sidebar-1',
  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. register_sidebar(
  163. array(
  164. 'name' => esc_html__( 'Footer 1', 'penscratch-2' ),
  165. 'id' => 'sidebar-2',
  166. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  167. 'after_widget' => '</aside>',
  168. 'before_title' => '<h1 class="widget-title">',
  169. 'after_title' => '</h1>',
  170. )
  171. );
  172. register_sidebar(
  173. array(
  174. 'name' => esc_html__( 'Footer 2', 'penscratch-2' ),
  175. 'id' => 'sidebar-3',
  176. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  177. 'after_widget' => '</aside>',
  178. 'before_title' => '<h1 class="widget-title">',
  179. 'after_title' => '</h1>',
  180. )
  181. );
  182. register_sidebar(
  183. array(
  184. 'name' => esc_html__( 'Footer 3', 'penscratch-2' ),
  185. 'id' => 'sidebar-4',
  186. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  187. 'after_widget' => '</aside>',
  188. 'before_title' => '<h1 class="widget-title">',
  189. 'after_title' => '</h1>',
  190. )
  191. );
  192. }
  193. add_action( 'widgets_init', 'penscratch_2_widgets_init' );
  194. /**
  195. * Enqueue scripts and styles.
  196. */
  197. function penscratch_2_scripts() {
  198. wp_enqueue_style( 'penscratch-2-style', get_stylesheet_uri(), array( 'penscratch-2-reset' ) );
  199. wp_enqueue_style( 'penscratch-2-fonts', penscratch_2_fonts_url(), array(), null );
  200. // Theme reset stylesheet
  201. wp_enqueue_style( 'penscratch-2-reset', get_theme_file_uri( '/css/reset.css' ), array(), '1.0' );
  202. // Theme form styles
  203. wp_enqueue_style( 'penscratch-2-reset', get_theme_file_uri( '/css/forms.css' ), array(), '1.0' );
  204. // Theme block stylesheet.
  205. wp_enqueue_style( 'penscratch-2-block-style', get_theme_file_uri( '/css/blocks.css' ), array( 'penscratch-2-style' ), '1.0' );
  206. wp_enqueue_script( 'penscratch-2-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  207. wp_enqueue_script( 'penscratch-2-scripts', get_template_directory_uri() . '/js/penscratch-2.js', array( 'jquery' ), '20170608', true );
  208. wp_enqueue_script( 'penscratch-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  209. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  210. wp_enqueue_script( 'comment-reply' );
  211. }
  212. }
  213. add_action( 'wp_enqueue_scripts', 'penscratch_2_scripts' );
  214. /**
  215. * Enqueue editor styles for Gutenberg
  216. */
  217. function penscratch_2_block_editor_styles() {
  218. // Block styles.
  219. wp_enqueue_style( 'penscratch-2-block-editor-style', get_theme_file_uri( '/css/editor-blocks.css' ) );
  220. // Fonts.
  221. wp_enqueue_style( 'penscratch-2-fonts-url', penscratch_2_fonts_url(), array(), null );
  222. }
  223. add_action( 'enqueue_block_editor_assets', 'penscratch_2_block_editor_styles' );
  224. /**
  225. * Register Google Fonts
  226. */
  227. function penscratch_2_fonts_url() {
  228. $fonts_url = '';
  229. /* Translators: If there are characters in your language that are not
  230. * supported by Roboto Slab, translate this to 'off'. Do not translate
  231. * into your own language.
  232. */
  233. $robotoslab = esc_html_x( 'on', 'Roboto Slab font: on or off', 'penscratch-2' );
  234. if ( 'off' !== $robotoslab ) {
  235. $font_families = array();
  236. $font_families[] = 'Roboto Slab:300,400,700';
  237. /**
  238. * A filter to enable child themes to add/change/omit font families.
  239. *
  240. * @param array $font_families An array of font families to be imploded for the Google Font API
  241. */
  242. $font_families = apply_filters( 'included_google_font_families', $font_families );
  243. $query_args = array(
  244. 'family' => urlencode( implode( '|', $font_families ) ),
  245. 'subset' => urlencode( 'latin,latin-ext' ),
  246. );
  247. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  248. }
  249. return $fonts_url;
  250. }
  251. /**
  252. * Implement the Custom Header feature.
  253. */
  254. require get_template_directory() . '/inc/custom-header.php';
  255. /**
  256. * Custom template tags for this theme.
  257. */
  258. require get_template_directory() . '/inc/template-tags.php';
  259. /**
  260. * Custom functions that act independently of the theme templates.
  261. */
  262. require get_template_directory() . '/inc/extras.php';
  263. /**
  264. * Customizer additions.
  265. */
  266. require get_template_directory() . '/inc/customizer.php';
  267. /**
  268. * Load Jetpack compatibility file.
  269. */
  270. require get_template_directory() . '/inc/jetpack.php';