functions.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * components functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Lodestar
  8. */
  9. if ( ! function_exists( 'lodestar_setup' ) ) :
  10. /**
  11. * Sets up theme defaults and registers support for various WordPress features.
  12. *
  13. * Note that this function is hooked into the aftercomponentsetup_theme hook, which
  14. * runs before the init hook. The init hook is too late for some features, such
  15. * as indicating support for post thumbnails.
  16. */
  17. function lodestar_setup() {
  18. /*
  19. * Make theme available for translation.
  20. * Translations can be filed in the /languages/ directory.
  21. * If you're building a theme based on components, use a find and replace
  22. * to change 'lodestar' to the name of your theme in all the template files.
  23. */
  24. load_theme_textdomain( 'lodestar', get_template_directory() . '/languages' );
  25. // Add default posts and comments RSS feed links to head.
  26. add_theme_support( 'automatic-feed-links' );
  27. /*
  28. * Let WordPress manage the document title.
  29. * By adding theme support, we declare that this theme does not use a
  30. * hard-coded <title> tag in the document head, and expect WordPress to
  31. * provide it for us.
  32. */
  33. add_theme_support( 'title-tag' );
  34. /*
  35. * Enable support for Post Thumbnails on posts and pages.
  36. *
  37. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  38. */
  39. add_theme_support( 'post-thumbnails' );
  40. add_image_size( 'lodestar-featured-image', 2000, 1200, true );
  41. add_image_size( 'lodestar-featured-archive-image', 700, 9999 );
  42. add_image_size( 'lodestar-portfolio-image', 2000, 9999 );
  43. add_image_size( 'lodestar-portfolio-archive-image', 900, 600, true );
  44. add_image_size( 'lodestar-thumbnail-avatar', 100, 100, true );
  45. add_image_size( 'lodestar-logo', 2400, 400 );
  46. // This theme uses wp_nav_menu() in one location.
  47. register_nav_menus( array(
  48. 'top' => esc_html__( 'Top', 'lodestar' ),
  49. ) );
  50. /*
  51. * Switch default core markup for search form, comment form, and comments
  52. * to output valid HTML5.
  53. */
  54. add_theme_support( 'html5', array(
  55. 'search-form',
  56. 'comment-form',
  57. 'comment-list',
  58. 'gallery',
  59. 'caption',
  60. ) );
  61. // Set up the WordPress core custom background feature.
  62. add_theme_support( 'custom-background', apply_filters( 'lodestar_custom_background_args', array(
  63. 'default-color' => 'ffffff',
  64. 'default-image' => '',
  65. ) ) );
  66. // Add support to selectively refresh widgets in Customizer
  67. add_theme_support( 'customize_selective_refresh_widgets' );
  68. // Add theme support for Custom Logo.
  69. add_theme_support( 'custom-logo', array(
  70. 'width' => 2400,
  71. 'height' => 400,
  72. 'flex-width' => true,
  73. 'flex-height' => true,
  74. 'header-text' => array( 'site-title', 'site-description' ),
  75. ) );
  76. // Add support for responsive embeds.
  77. add_theme_support( 'responsive-embeds' );
  78. // Add support for full and wide align images.
  79. add_theme_support( 'align-wide' );
  80. }
  81. endif;
  82. add_action( 'after_setup_theme', 'lodestar_setup' );
  83. /**
  84. * Set the content width in pixels, based on the theme's design and stylesheet.
  85. *
  86. * Priority 0 to make it available to lower priority callbacks.
  87. *
  88. * @global int $content_width
  89. */
  90. function lodestar_content_width() {
  91. $GLOBALS['content_width'] = apply_filters( 'lodestar_content_width', 700 );
  92. }
  93. add_action( 'after_setup_theme', 'lodestar_content_width', 0 );
  94. /**
  95. * Custom function that modifies the_custom_logo output slightly
  96. */
  97. function lodestar_the_custom_logo() {
  98. if ( has_custom_logo() ) {
  99. $custom_logo_id = get_theme_mod( 'custom_logo' );
  100. $custom_logo_attr = array(
  101. 'class' => 'site-logo',
  102. 'itemprop' => 'logo',
  103. );
  104. printf( '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>',
  105. esc_url( home_url( '/' ) ),
  106. wp_get_attachment_image( $custom_logo_id , 'lodestar-logo', false, $custom_logo_attr )
  107. );
  108. }
  109. }
  110. /**
  111. * Register custom fonts
  112. */
  113. function lodestar_fonts_url() {
  114. $fonts_url = '';
  115. /* Translators: If there are characters in your language that are not
  116. * supported by Work Sans, translate this to 'off'. Do not translate
  117. * into your own language.
  118. */
  119. $work_sans = esc_html_x( 'on', 'work_sans font: on or off', 'lodestar' );
  120. /* Translators: If there are characters in your language that are not
  121. * supported by Karla, translate this to 'off'. Do not translate
  122. * into your own language.
  123. */
  124. $karla = esc_html_x( 'on', 'Karla font: on or off', 'lodestar' );
  125. if ( 'off' !== $work_sans || 'off' !== $karla ) {
  126. $font_families = array();
  127. if ( 'off' !== $work_sans ) {
  128. $font_families[] = 'Work Sans:800';
  129. }
  130. if ( 'off' !== $karla ) {
  131. $font_families[] = 'Karla:400,400italic,700,700italic';
  132. }
  133. $query_args = array(
  134. 'family' => urlencode( implode( '|', $font_families ) ),
  135. 'subset' => urlencode( 'latin,latin-ext' ),
  136. );
  137. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  138. }
  139. return esc_url_raw( $fonts_url );
  140. }
  141. /**
  142. * Register widget area.
  143. *
  144. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  145. */
  146. function lodestar_widgets_init() {
  147. register_sidebar( array(
  148. 'name' => esc_html__( 'Sidebar', 'lodestar' ),
  149. 'id' => 'sidebar-1',
  150. 'description' => '',
  151. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  152. 'after_widget' => '</section>',
  153. 'before_title' => '<h2 class="widget-title">',
  154. 'after_title' => '</h2>',
  155. ) );
  156. register_sidebar( array(
  157. 'name' => esc_html__( 'Footer 1', 'lodestar' ),
  158. 'id' => 'sidebar-2',
  159. 'description' => '',
  160. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  161. 'after_widget' => '</section>',
  162. 'before_title' => '<h2 class="widget-title">',
  163. 'after_title' => '</h2>',
  164. ) );
  165. register_sidebar( array(
  166. 'name' => esc_html__( 'Footer 2', 'lodestar' ),
  167. 'id' => 'sidebar-3',
  168. 'description' => '',
  169. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  170. 'after_widget' => '</section>',
  171. 'before_title' => '<h2 class="widget-title">',
  172. 'after_title' => '</h2>',
  173. ) );
  174. register_sidebar( array(
  175. 'name' => esc_html__( 'Footer 3', 'lodestar' ),
  176. 'id' => 'sidebar-4',
  177. 'description' => '',
  178. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  179. 'after_widget' => '</section>',
  180. 'before_title' => '<h2 class="widget-title">',
  181. 'after_title' => '</h2>',
  182. ) );
  183. // echo esc_attr( lodestar_widget_column_class( 'sidebar-1' ) );
  184. }
  185. add_action( 'widgets_init', 'lodestar_widgets_init' );
  186. /**
  187. * Wrap avatars in div for easier styling
  188. */
  189. function lodestar_get_avatar( $avatar ) {
  190. if ( ! is_admin() ) {
  191. $avatar = '<span class="avatar-container">' . $avatar . '</span>';
  192. }
  193. return $avatar;
  194. }
  195. add_filter( 'get_avatar', 'lodestar_get_avatar', 10, 5 );
  196. /**
  197. * Use front-page.php when Front page displayes is set to a static page.
  198. *
  199. * @param string $template front-page.php.
  200. *
  201. * @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
  202. */
  203. function lodestar_front_page_template( $template ) {
  204. return is_home() ? '' : $template;
  205. }
  206. add_filter( 'frontpage_template', 'lodestar_front_page_template' );
  207. /**
  208. * Enqueue scripts and styles.
  209. */
  210. function lodestar_scripts() {
  211. wp_enqueue_style( 'lodestar-style', get_stylesheet_uri() );
  212. // Theme block stylesheet.
  213. wp_enqueue_style( 'lodestar-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'lodestar-style' ), '1.0' );
  214. wp_enqueue_style( 'lodestar_fonts_url', lodestar_fonts_url(), array(), null );
  215. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/fonts/genericons.css', array(), null );
  216. wp_enqueue_script( 'lodestar-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20151215', true );
  217. wp_enqueue_script( 'lodestar-global', get_template_directory_uri() . '/assets/js/global.js', array( 'jquery' ), '20151215', true );
  218. wp_enqueue_script( 'lodestar-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
  219. // Scroll effects (only loaded on front page in Customizer)
  220. if ( lodestar_is_frontpage() && is_customize_preview() ) :
  221. wp_enqueue_script( 'scrollTo', get_template_directory_uri() . '/assets/js/jquery.scrollTo.js', array( 'jquery' ), '20151030', true );
  222. endif;
  223. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  224. wp_enqueue_script( 'comment-reply' );
  225. }
  226. // Portfolio navigation (only loaded on Portfolio Template)
  227. if ( is_page_template( 'templates/portfolio-page.php' ) ) :
  228. wp_enqueue_script( 'lazyload', get_template_directory_uri() . '/assets/js/jquery.lazyload.js', array( 'jquery' ), '20160719', true );
  229. wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/js/isotope.pkgd.js', array( 'jquery' ), '20160719', true );
  230. wp_enqueue_script( 'lodestar-portfolio-page', get_template_directory_uri() . '/assets/js/portfolio-page.js', array( 'jquery', 'isotope', 'lazyload' ), '20160719', true );
  231. endif;
  232. }
  233. add_action( 'wp_enqueue_scripts', 'lodestar_scripts' );
  234. /**
  235. * Enqueue editor styles for Gutenberg
  236. */
  237. function lodestar_block_editor_styles() {
  238. // Block styles.
  239. wp_enqueue_style( 'lodestar-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ) );
  240. // Fonts.
  241. wp_enqueue_style( 'lodestar-fonts-url', lodestar_fonts_url(), array(), null );
  242. }
  243. add_action( 'enqueue_block_editor_assets', 'lodestar_block_editor_styles' );
  244. /**
  245. * Implement the Custom Header feature.
  246. */
  247. require get_template_directory() . '/inc/custom-header.php';
  248. /**
  249. * Custom template tags for this theme.
  250. */
  251. require get_template_directory() . '/inc/template-tags.php';
  252. /**
  253. * Custom functions that act independently of the theme templates.
  254. */
  255. require get_template_directory() . '/inc/extras.php';
  256. /**
  257. * Customizer additions.
  258. */
  259. require get_template_directory() . '/inc/customizer.php';
  260. /**
  261. * Load Jetpack compatibility file.
  262. */
  263. require get_template_directory() . '/inc/jetpack.php';
  264. /**
  265. * Load WooCommerce compatibility file.
  266. */
  267. if ( class_exists( 'WooCommerce' ) ) {
  268. require( get_template_directory() . '/inc/woocommerce.php' );
  269. }