functions.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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', array(
  52. array(
  53. 'name' => esc_html__( 'Black', 'intergalactic-2' ),
  54. 'slug' => 'black',
  55. 'color' => '#222222',
  56. ),
  57. array(
  58. 'name' => esc_html__( 'Dark Gray', 'intergalactic-2' ),
  59. 'slug' => 'dark-gray',
  60. 'color' => '#333333',
  61. ),
  62. array(
  63. 'name' => esc_html__( 'Light Gray', 'intergalactic-2' ),
  64. 'slug' => 'light-gray',
  65. 'color' => '#cccccc',
  66. ),
  67. array(
  68. 'name' => esc_html__( 'White', 'intergalactic-2' ),
  69. 'slug' => 'white',
  70. 'color' => '#ffffff',
  71. ),
  72. array(
  73. 'name' => esc_html__( 'Purple', 'intergalactic-2' ),
  74. 'slug' => 'purple',
  75. 'color' => '#81699b',
  76. ),
  77. array(
  78. 'name' => esc_html__( 'Dark Purple', 'intergalactic-2' ),
  79. 'slug' => 'dark-purple',
  80. 'color' => '#553a72',
  81. ),
  82. array(
  83. 'name' => esc_html__( 'Dark Green', 'intergalactic-2' ),
  84. 'slug' => 'dark-green',
  85. 'color' => '#557d73',
  86. ),
  87. )
  88. );
  89. /*
  90. * Enable support for Post Thumbnails on posts and pages.
  91. *
  92. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  93. */
  94. add_theme_support( 'post-thumbnails' );
  95. add_image_size( 'intergalactic-2-large', '1440', '960', false );
  96. // Enable support for custom logo.
  97. add_theme_support( 'custom-logo', array(
  98. 'height' => 400,
  99. 'width' => 1200,
  100. 'flex-height' => true,
  101. 'flex-width' => true
  102. ) );
  103. // This theme uses wp_nav_menu() in two locations.
  104. register_nav_menus( array(
  105. 'menu-1' => esc_html__( 'Slide-Out Menu', 'intergalactic-2' ),
  106. ) );
  107. /*
  108. * Switch default core markup for search form, comment form, and comments
  109. * to output valid HTML5.
  110. */
  111. add_theme_support( 'html5', array(
  112. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
  113. ) );
  114. // Setup the WordPress core custom background feature.
  115. add_theme_support( 'custom-background', apply_filters( 'intergalactic_2_custom_background_args', array(
  116. 'default-color' => 'ffffff',
  117. 'default-image' => '',
  118. ) ) );
  119. // Add theme support for selective refresh for widgets.
  120. add_theme_support( 'customize-selective-refresh-widgets' );
  121. }
  122. endif; // intergalactic_2_setup
  123. add_action( 'after_setup_theme', 'intergalactic_2_setup' );
  124. /**
  125. * Register widget area.
  126. *
  127. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  128. */
  129. function intergalactic_2_widgets_init() {
  130. register_sidebar( array(
  131. 'name' => esc_html__( 'Sidebar', 'intergalactic-2' ),
  132. 'id' => 'sidebar-1',
  133. 'description' => '',
  134. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  135. 'after_widget' => '</aside>',
  136. 'before_title' => '<h1 class="widget-title">',
  137. 'after_title' => '</h1>',
  138. ) );
  139. register_sidebar( array(
  140. 'name' => esc_html__( 'Footer 1', 'intergalactic-2' ),
  141. 'id' => 'sidebar-2',
  142. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  143. 'after_widget' => '</aside>',
  144. 'before_title' => '<h1 class="widget-title">',
  145. 'after_title' => '</h1>',
  146. ) );
  147. register_sidebar( array(
  148. 'name' => esc_html__( 'Footer 2', 'intergalactic-2' ),
  149. 'id' => 'sidebar-3',
  150. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  151. 'after_widget' => '</aside>',
  152. 'before_title' => '<h1 class="widget-title">',
  153. 'after_title' => '</h1>',
  154. ) );
  155. register_sidebar( array(
  156. 'name' => esc_html__( 'Footer 3', 'intergalactic-2' ),
  157. 'id' => 'sidebar-4',
  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. add_action( 'widgets_init', 'intergalactic_2_widgets_init' );
  165. /**
  166. * Enqueue scripts and styles.
  167. */
  168. function intergalactic_2_scripts() {
  169. wp_enqueue_style( 'intergalactic-2-style', get_stylesheet_uri() );
  170. // Gutenberg styles
  171. wp_enqueue_style( 'intergalactic-2-blocks', get_template_directory_uri() . '/blocks.css' );
  172. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  173. wp_enqueue_script( 'intergalactic-2-script', get_template_directory_uri() . '/js/intergalactic-2.js', array( 'jquery' ), '20170428', true );
  174. wp_enqueue_script( 'intergalactic-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  175. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  176. wp_enqueue_script( 'comment-reply' );
  177. }
  178. wp_enqueue_style( 'intergalactic-2-lato', intergalactic_2_fonts_url(), array(), null );
  179. }
  180. add_action( 'wp_enqueue_scripts', 'intergalactic_2_scripts' );
  181. /**
  182. * Gutenberg Editor Styles
  183. */
  184. function intergalactic_2_editor_styles() {
  185. wp_enqueue_style( 'intergalactic-2-editor-block-style', get_template_directory_uri() . '/editor-blocks.css');
  186. wp_enqueue_style( 'intergalactic-2-lato', intergalactic_2_fonts_url() );
  187. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
  188. }
  189. add_action( 'enqueue_block_editor_assets', 'intergalactic_2_editor_styles' );
  190. /**
  191. * Register Google Fonts
  192. */
  193. function intergalactic_2_fonts_url() {
  194. $fonts_url = '';
  195. /* Translators: If there are characters in your language that are not
  196. * supported by Lato, translate this to 'off'. Do not translate
  197. * into your own language.
  198. */
  199. $arimo = esc_html_x( 'on', 'Lato font: on or off', 'intergalactic-2' );
  200. if ( 'off' !== $arimo ) {
  201. $font_families = array();
  202. $font_families[] = 'Lato:300,400,700,300italic,400italic,700italic&subset=latin,latin-ext';
  203. $query_args = array(
  204. 'family' => urlencode( implode( '|', $font_families ) ),
  205. 'subset' => urlencode( 'latin,latin-ext' ),
  206. );
  207. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  208. }
  209. return $fonts_url;
  210. }
  211. if ( ! function_exists( 'intergalactic_2_continue_reading_link' ) ) :
  212. /**
  213. * Returns an ellipsis and "Continue reading" plus off-screen title link for excerpts
  214. */
  215. function intergalactic_2_continue_reading_link() {
  216. 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>';
  217. }
  218. endif; // intergalactic_2_continue_reading_link
  219. /**
  220. * Always display a Read More link when using the_excerpt()
  221. */
  222. function intergalactic_2_excerpt_more( $output ) {
  223. return $output . intergalactic_2_continue_reading_link();
  224. }
  225. add_filter( 'the_excerpt', 'intergalactic_2_excerpt_more' );
  226. /**
  227. * Implement the Custom Header feature.
  228. */
  229. require get_template_directory() . '/inc/custom-header.php';
  230. /**
  231. * Custom template tags for this theme.
  232. */
  233. require get_template_directory() . '/inc/template-tags.php';
  234. /**
  235. * Custom functions that act independently of the theme templates.
  236. */
  237. require get_template_directory() . '/inc/extras.php';
  238. /**
  239. * Customizer additions.
  240. */
  241. require get_template_directory() . '/inc/customizer.php';
  242. /**
  243. * Load Jetpack compatibility file.
  244. */
  245. require get_template_directory() . '/inc/jetpack.php';