functions.php 9.2 KB

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