functions.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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( array(
  41. 'menu-1' => esc_html__( 'Header', 'penscratch-2' ),
  42. ) );
  43. add_editor_style( array( 'editor-style.css', penscratch_2_fonts_url() ) );
  44. /*
  45. * Switch default core markup for search form, comment form, and comments
  46. * to output valid HTML5.
  47. */
  48. add_theme_support( 'html5', array(
  49. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  50. ) );
  51. // Enable support for custom logo.
  52. add_theme_support( 'custom-logo', array(
  53. 'height' => 400,
  54. 'width' => 1200,
  55. 'flex-height' => true,
  56. 'flex-width' => true
  57. ) );
  58. // Add theme support for selective refresh for widgets.
  59. add_theme_support( 'customize-selective-refresh-widgets' );
  60. // Setup the WordPress core custom background feature.
  61. add_theme_support( 'custom-background', apply_filters( 'penscratch_2_custom_background_args', array(
  62. 'default-color' => 'eeeeee',
  63. 'default-image' => '',
  64. ) ) );
  65. // Add support for responsive embeds.
  66. add_theme_support( 'responsive-embeds' );
  67. // Add custom colors to Gutenberg
  68. add_theme_support(
  69. 'editor-color-palette', array(
  70. array(
  71. 'name' => esc_html__( 'Dark Green', 'penscratch-2' ),
  72. 'slug' => 'dark-green',
  73. 'color' => '#1c7c7c',
  74. ),
  75. array(
  76. 'name' => esc_html__( 'Dark Gray', 'penscratch-2' ),
  77. 'slug' => 'dark-gray',
  78. 'color' => '#666',
  79. ),
  80. array(
  81. 'name' => esc_html__( 'Medium Gray', 'penscratch-2' ),
  82. 'slug' => 'medium-gray',
  83. 'color' => '#999',
  84. ),
  85. array(
  86. 'name' => esc_html__( 'Light Gray', 'penscratch-2' ),
  87. 'slug' => 'light-gray',
  88. 'color' => '#eee',
  89. ),
  90. array(
  91. 'name' => esc_html__( 'White', 'penscratch-2' ),
  92. 'slug' => 'white',
  93. 'color' => '#fff',
  94. ),
  95. )
  96. );
  97. }
  98. endif; // penscratch_2_setup
  99. add_action( 'after_setup_theme', 'penscratch_2_setup' );
  100. /**
  101. * Set the content width in pixels, based on the theme's design and stylesheet.
  102. *
  103. * Priority 0 to make it available to lower priority callbacks.
  104. *
  105. * @global int $content_width
  106. */
  107. function penscratch_2_content_width() {
  108. $GLOBALS['content_width'] = apply_filters( 'penscratch_2_content_width', 656 );
  109. }
  110. add_action( 'after_setup_theme', 'penscratch_2_content_width', 0 );
  111. function penscratch_2_adjust_content_width() {
  112. global $content_width;
  113. if ( is_page_template( 'templates/full-width-page.php' ) ) {
  114. $content_width = 937;
  115. }
  116. }
  117. add_action( 'template_redirect', 'penscratch_2_adjust_content_width' );
  118. /**
  119. * Register widget area.
  120. *
  121. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  122. */
  123. function penscratch_2_widgets_init() {
  124. register_sidebar( array(
  125. 'name' => esc_html__( 'Sidebar', 'penscratch-2' ),
  126. 'id' => 'sidebar-1',
  127. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  128. 'after_widget' => '</aside>',
  129. 'before_title' => '<h1 class="widget-title">',
  130. 'after_title' => '</h1>',
  131. ) );
  132. register_sidebar( array(
  133. 'name' => esc_html__( 'Footer 1', 'penscratch-2' ),
  134. 'id' => 'sidebar-2',
  135. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  136. 'after_widget' => '</aside>',
  137. 'before_title' => '<h1 class="widget-title">',
  138. 'after_title' => '</h1>',
  139. ) );
  140. register_sidebar( array(
  141. 'name' => esc_html__( 'Footer 2', 'penscratch-2' ),
  142. 'id' => 'sidebar-3',
  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. register_sidebar( array(
  149. 'name' => esc_html__( 'Footer 3', 'penscratch-2' ),
  150. 'id' => 'sidebar-4',
  151. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  152. 'after_widget' => '</aside>',
  153. 'before_title' => '<h1 class="widget-title">',
  154. 'after_title' => '</h1>',
  155. ) );
  156. }
  157. add_action( 'widgets_init', 'penscratch_2_widgets_init' );
  158. /**
  159. * Enqueue scripts and styles.
  160. */
  161. function penscratch_2_scripts() {
  162. wp_enqueue_style( 'penscratch-2-style', get_stylesheet_uri() );
  163. wp_enqueue_style( 'penscratch-2-fonts', penscratch_2_fonts_url(), array(), null );
  164. // Theme block stylesheet.
  165. wp_enqueue_style( 'penscratch-2-block-style', get_theme_file_uri( '/css/blocks.css' ), array( 'penscratch-2-style' ), '1.0' );
  166. wp_enqueue_script( 'penscratch-2-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  167. wp_enqueue_script( 'penscratch-2-scripts', get_template_directory_uri() . '/js/penscratch-2.js', array( 'jquery' ), '20170608', true );
  168. wp_enqueue_script( 'penscratch-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  169. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  170. wp_enqueue_script( 'comment-reply' );
  171. }
  172. }
  173. add_action( 'wp_enqueue_scripts', 'penscratch_2_scripts' );
  174. /**
  175. * Enqueue editor styles for Gutenberg
  176. */
  177. function penscratch_2_block_editor_styles() {
  178. // Block styles.
  179. wp_enqueue_style( 'penscratch-2-block-editor-style', get_theme_file_uri( '/css/editor-blocks.css' ) );
  180. // Fonts.
  181. wp_enqueue_style( 'penscratch-2-fonts-url', penscratch_2_fonts_url(), array(), null );
  182. }
  183. add_action( 'enqueue_block_editor_assets', 'penscratch_2_block_editor_styles' );
  184. /**
  185. * Register Google Fonts
  186. */
  187. function penscratch_2_fonts_url() {
  188. $fonts_url = '';
  189. /* Translators: If there are characters in your language that are not
  190. * supported by Roboto Slab, translate this to 'off'. Do not translate
  191. * into your own language.
  192. */
  193. $robotoslab = esc_html_x( 'on', 'Roboto Slab font: on or off', 'penscratch-2' );
  194. if ( 'off' !== $robotoslab ) {
  195. $font_families = array();
  196. $font_families[] = 'Roboto Slab:300,400,700';
  197. $query_args = array(
  198. 'family' => urlencode( implode( '|', $font_families ) ),
  199. 'subset' => urlencode( 'latin,latin-ext' ),
  200. );
  201. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  202. }
  203. return $fonts_url;
  204. }
  205. /**
  206. * Implement the Custom Header feature.
  207. */
  208. require get_template_directory() . '/inc/custom-header.php';
  209. /**
  210. * Custom template tags for this theme.
  211. */
  212. require get_template_directory() . '/inc/template-tags.php';
  213. /**
  214. * Custom functions that act independently of the theme templates.
  215. */
  216. require get_template_directory() . '/inc/extras.php';
  217. /**
  218. * Customizer additions.
  219. */
  220. require get_template_directory() . '/inc/customizer.php';
  221. /**
  222. * Load Jetpack compatibility file.
  223. */
  224. require get_template_directory() . '/inc/jetpack.php';