functions.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 support for custom padding.
  86. add_theme_support( 'custom-spacing' );
  87. // Add custom colors to Gutenberg
  88. add_theme_support(
  89. 'editor-color-palette',
  90. array(
  91. array(
  92. 'name' => esc_html__( 'Dark Green', 'penscratch-2' ),
  93. 'slug' => 'dark-green',
  94. 'color' => '#1c7c7c',
  95. ),
  96. array(
  97. 'name' => esc_html__( 'Dark Gray', 'penscratch-2' ),
  98. 'slug' => 'dark-gray',
  99. 'color' => '#666',
  100. ),
  101. array(
  102. 'name' => esc_html__( 'Medium Gray', 'penscratch-2' ),
  103. 'slug' => 'medium-gray',
  104. 'color' => '#999',
  105. ),
  106. array(
  107. 'name' => esc_html__( 'Light Gray', 'penscratch-2' ),
  108. 'slug' => 'light-gray',
  109. 'color' => '#eee',
  110. ),
  111. array(
  112. 'name' => esc_html__( 'White', 'penscratch-2' ),
  113. 'slug' => 'white',
  114. 'color' => '#fff',
  115. ),
  116. )
  117. );
  118. add_theme_support( 'editor-styles' );
  119. add_editor_style(
  120. array(
  121. 'style.css',
  122. '/css/blocks.css',
  123. '/css/editor-blocks.css',
  124. penscratch_2_fonts_url(),
  125. )
  126. );
  127. }
  128. endif; // penscratch_2_setup
  129. add_action( 'after_setup_theme', 'penscratch_2_setup' );
  130. /**
  131. * Set the content width in pixels, based on the theme's design and stylesheet.
  132. *
  133. * Priority 0 to make it available to lower priority callbacks.
  134. *
  135. * @global int $content_width
  136. */
  137. function penscratch_2_content_width() {
  138. $GLOBALS['content_width'] = apply_filters( 'penscratch_2_content_width', 656 );
  139. }
  140. add_action( 'after_setup_theme', 'penscratch_2_content_width', 0 );
  141. function penscratch_2_adjust_content_width() {
  142. global $content_width;
  143. if ( is_page_template( 'templates/full-width-page.php' ) ) {
  144. $content_width = 937;
  145. }
  146. }
  147. add_action( 'template_redirect', 'penscratch_2_adjust_content_width' );
  148. /**
  149. * Register widget area.
  150. *
  151. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  152. */
  153. function penscratch_2_widgets_init() {
  154. register_sidebar(
  155. array(
  156. 'name' => esc_html__( 'Sidebar', 'penscratch-2' ),
  157. 'id' => 'sidebar-1',
  158. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  159. 'after_widget' => '</aside>',
  160. 'before_title' => '<h1 class="widget-title">',
  161. 'after_title' => '</h1>',
  162. )
  163. );
  164. register_sidebar(
  165. array(
  166. 'name' => esc_html__( 'Footer 1', 'penscratch-2' ),
  167. 'id' => 'sidebar-2',
  168. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  169. 'after_widget' => '</aside>',
  170. 'before_title' => '<h1 class="widget-title">',
  171. 'after_title' => '</h1>',
  172. )
  173. );
  174. register_sidebar(
  175. array(
  176. 'name' => esc_html__( 'Footer 2', 'penscratch-2' ),
  177. 'id' => 'sidebar-3',
  178. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  179. 'after_widget' => '</aside>',
  180. 'before_title' => '<h1 class="widget-title">',
  181. 'after_title' => '</h1>',
  182. )
  183. );
  184. register_sidebar(
  185. array(
  186. 'name' => esc_html__( 'Footer 3', 'penscratch-2' ),
  187. 'id' => 'sidebar-4',
  188. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  189. 'after_widget' => '</aside>',
  190. 'before_title' => '<h1 class="widget-title">',
  191. 'after_title' => '</h1>',
  192. )
  193. );
  194. }
  195. add_action( 'widgets_init', 'penscratch_2_widgets_init' );
  196. /**
  197. * Enqueue scripts and styles.
  198. */
  199. function penscratch_2_scripts() {
  200. wp_enqueue_style( 'penscratch-2-style', get_stylesheet_uri(), array( 'penscratch-2-reset' ) );
  201. wp_enqueue_style( 'penscratch-2-fonts', penscratch_2_fonts_url(), array(), null );
  202. // Theme reset stylesheet
  203. wp_enqueue_style( 'penscratch-2-reset', get_theme_file_uri( '/css/reset.css' ), array(), '1.0' );
  204. // Theme form styles
  205. wp_enqueue_style( 'penscratch-2-reset', get_theme_file_uri( '/css/forms.css' ), array(), '1.0' );
  206. // Theme block stylesheet.
  207. wp_enqueue_style( 'penscratch-2-block-style', get_theme_file_uri( '/css/blocks.css' ), array( 'penscratch-2-style' ), '1.0' );
  208. wp_enqueue_script( 'penscratch-2-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  209. wp_enqueue_script( 'penscratch-2-scripts', get_template_directory_uri() . '/js/penscratch-2.js', array( 'jquery' ), '20170608', true );
  210. wp_enqueue_script( 'penscratch-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  211. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  212. wp_enqueue_script( 'comment-reply' );
  213. }
  214. }
  215. add_action( 'wp_enqueue_scripts', 'penscratch_2_scripts' );
  216. /**
  217. * Enqueue editor styles for Gutenberg
  218. */
  219. function penscratch_2_block_editor_styles() {
  220. // Block styles.
  221. wp_enqueue_style( 'penscratch-2-block-editor-style', get_theme_file_uri( '/css/editor-blocks.css' ) );
  222. // Fonts.
  223. wp_enqueue_style( 'penscratch-2-fonts-url', penscratch_2_fonts_url(), array(), null );
  224. }
  225. add_action( 'enqueue_block_editor_assets', 'penscratch_2_block_editor_styles' );
  226. /**
  227. * Register Google Fonts
  228. */
  229. function penscratch_2_fonts_url() {
  230. $fonts_url = '';
  231. /* Translators: If there are characters in your language that are not
  232. * supported by Roboto Slab, translate this to 'off'. Do not translate
  233. * into your own language.
  234. */
  235. $robotoslab = esc_html_x( 'on', 'Roboto Slab font: on or off', 'penscratch-2' );
  236. if ( 'off' !== $robotoslab ) {
  237. $font_families = array();
  238. $font_families[] = 'Roboto Slab:300,400,700';
  239. /**
  240. * A filter to enable child themes to add/change/omit font families.
  241. *
  242. * @param array $font_families An array of font families to be imploded for the Google Font API
  243. */
  244. $font_families = apply_filters( 'included_google_font_families', $font_families );
  245. $query_args = array(
  246. 'family' => urlencode( implode( '|', $font_families ) ),
  247. 'subset' => urlencode( 'latin,latin-ext' ),
  248. );
  249. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  250. }
  251. return $fonts_url;
  252. }
  253. /**
  254. * Implement the Custom Header feature.
  255. */
  256. require get_template_directory() . '/inc/custom-header.php';
  257. /**
  258. * Custom template tags for this theme.
  259. */
  260. require get_template_directory() . '/inc/template-tags.php';
  261. /**
  262. * Custom functions that act independently of the theme templates.
  263. */
  264. require get_template_directory() . '/inc/extras.php';
  265. /**
  266. * Customizer additions.
  267. */
  268. require get_template_directory() . '/inc/customizer.php';
  269. /**
  270. * Load Jetpack compatibility file.
  271. */
  272. require get_template_directory() . '/inc/jetpack.php';