functions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. /**
  3. * This file adds all the functions to the Captivating theme.
  4. *
  5. * @package Captivating
  6. * @link http://restored316designs.com/themes
  7. * @author Lauren Gaige // Restored 316 LLC
  8. * @copyright Copyright (c) 2015, Restored 316 LLC, Released 08/09/2017
  9. * @license GPL-2.0+
  10. */
  11. //* Start the engine
  12. include_once( get_template_directory() . '/lib/init.php' );
  13. //* Setup Theme
  14. include_once( get_stylesheet_directory() . '/lib/theme-defaults.php' );
  15. //* Add Color selections to WordPress Theme Customizer
  16. require_once( get_stylesheet_directory() . '/lib/customize.php' );
  17. //* Include Customizer CSS
  18. include_once( get_stylesheet_directory() . '/lib/output.php' );
  19. //* Add Widget Spaces
  20. require_once( get_stylesheet_directory() . '/lib/widgets.php' );
  21. //* Install Plugins
  22. require_once( get_stylesheet_directory() . '/lib/plugins/tgm-plugin-activation/register-plugins.php' );
  23. //* Child theme (do not remove)
  24. define( 'CHILD_THEME_NAME', 'captivating' );
  25. define( 'CHILD_THEME_URL', 'http://restored316designs.com' );
  26. define( 'CHILD_THEME_VERSION', '1.0.0' );
  27. //* Loads Responsive Menu, Google Fonts, Icons, and other scripts
  28. add_action( 'wp_enqueue_scripts', 'captivating_enqueue_scripts' );
  29. function captivating_enqueue_scripts() {
  30. wp_enqueue_style( 'google-font', '//fonts.googleapis.com/css?family=Montserrat:300,300i,400,700,700i|Open+Sans:400,400i,700,700i|Playfair+Display:400,400i,700,700i|Poppins|Satisfy', array() );
  31. wp_enqueue_style( 'ionicons', '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', array(), CHILD_THEME_VERSION );
  32. wp_enqueue_style( 'dashicons' );
  33. wp_enqueue_script( 'captivating-global-script', get_bloginfo( 'stylesheet_directory' ) . '/js/global.js', array( 'jquery' ), '1.0.0' );
  34. wp_enqueue_script( 'match-height', get_stylesheet_directory_uri() . '/js/jquery.matchHeight-min.js', array( 'jquery' ), '1.0.0', true );
  35. wp_enqueue_script( 'match-height-init', get_stylesheet_directory_uri() . '/js/matchheight-init.js', array( 'match-height' ), '1.0.0', true );
  36. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
  37. wp_enqueue_script( 'captivating-responsive-menu', get_stylesheet_directory_uri() . "/js/responsive-menus{$suffix}.js", array( 'jquery' ), CHILD_THEME_VERSION, true );
  38. wp_localize_script(
  39. 'captivating-responsive-menu',
  40. 'genesis_responsive_menu',
  41. captivating_responsive_menu_settings()
  42. );
  43. }
  44. // Define our responsive menu settings.
  45. function captivating_responsive_menu_settings() {
  46. $settings = array(
  47. 'mainMenu' => __( 'Menu', 'captivating' ),
  48. 'menuIconClass' => 'dashicons-before dashicons-menu',
  49. 'subMenu' => __( 'Submenu', 'captivating' ),
  50. 'subMenuIconsClass' => 'dashicons-before dashicons-arrow-down-alt2',
  51. 'menuClasses' => array(
  52. 'combine' => array(
  53. '.nav-header',
  54. '.nav-header-left',
  55. '.nav-header-right',
  56. '.nav-secondary',
  57. '.nav-primary',
  58. ),
  59. 'others' => array(
  60. '.nav-footer',
  61. ),
  62. ),
  63. );
  64. return $settings;
  65. }
  66. //* Add support for footer menu & rename menus
  67. add_theme_support ( 'genesis-menus' , array (
  68. 'primary' => 'Above Header Menu',
  69. 'secondary' => 'Below Header Menu',
  70. 'header-left' => 'Header Left',
  71. 'header-right' => 'Header Right',
  72. 'footer' => 'Footer Menu'
  73. ) );
  74. //* Add HTML5 markup structure
  75. add_theme_support( 'html5' );
  76. //* Add new featured image sizes
  77. add_image_size( 'square-entry-image', 400, 400, TRUE );
  78. add_image_size( 'vertical-entry-image', 400, 600, TRUE );
  79. add_image_size( 'horizontal-entry-image', 820, 550, TRUE );
  80. //* Add support for 3-column footer widgets
  81. add_theme_support( 'genesis-footer-widgets', 3 );
  82. //* Add viewport meta tag for mobile browsers
  83. add_theme_support( 'genesis-responsive-viewport' );
  84. //* Add support for custom background
  85. add_theme_support( 'custom-background', array(
  86. 'default-color' => 'FFFFFF',
  87. ));
  88. //* Add support for after entry widget
  89. add_theme_support( 'genesis-after-entry-widget-area' );
  90. //* Add support for custom header
  91. add_theme_support( 'custom-header', array(
  92. 'width' => 2000,
  93. 'height' => 1562,
  94. 'header-selector' => '.site-title a',
  95. 'header-text' => false,
  96. ) );
  97. //* Remove the site description
  98. remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
  99. //* Unregister layout settings
  100. genesis_unregister_layout( 'content-sidebar-sidebar' );
  101. genesis_unregister_layout( 'sidebar-content-sidebar' );
  102. genesis_unregister_layout( 'sidebar-sidebar-content' );
  103. //* Unregister secondary sidebar
  104. unregister_sidebar( 'sidebar-alt' );
  105. //* Reposition the primary navigation menu
  106. remove_action( 'genesis_after_header', 'genesis_do_nav' );
  107. add_action( 'genesis_before_header', 'genesis_do_nav', 7 );
  108. //* Add search form to navigation
  109. add_filter( 'wp_nav_menu_items', 'captivating_primary_nav_extras', 10, 2 );
  110. function captivating_primary_nav_extras( $menu, $args ) {
  111. if ( 'primary' !== $args->theme_location ) {
  112. return $menu;
  113. }
  114. ob_start();
  115. get_search_form();
  116. $search = ob_get_clean();
  117. $menu .= '<li class="right search">' . $search . '</li>';
  118. return $menu;
  119. }
  120. //* Add widget to primary navigation
  121. add_filter( 'genesis_nav_items', 'captivating_social_icons', 10, 2 );
  122. add_filter( 'wp_nav_menu_items', 'captivating_social_icons', 10, 2 );
  123. function captivating_social_icons($menu, $args) {
  124. $args = (array)$args;
  125. if ( 'primary' !== $args['theme_location'] )
  126. return $menu;
  127. ob_start();
  128. genesis_widget_area('nav-social-menu');
  129. $social = ob_get_clean();
  130. return $menu . $social;
  131. }
  132. //* Hook menu to left of Logo
  133. add_action( 'genesis_header', 'captivating_header_left_menu', 6 );
  134. function captivating_header_left_menu() {
  135. genesis_nav_menu( array(
  136. 'theme_location' => 'header-left',
  137. 'depth' => 2,
  138. ) );
  139. }
  140. //* Hook menu to right of Logo
  141. add_action( 'genesis_header', 'captivating_header_right_menu', 9 );
  142. function captivating_header_right_menu() {
  143. genesis_nav_menu( array(
  144. 'theme_location' => 'header-right',
  145. 'depth' => 2,
  146. ) );
  147. }
  148. //* Hook menu in footer
  149. add_action( 'genesis_before_footer', 'captivating_footer_menu', 7 );
  150. function captivating_footer_menu() {
  151. genesis_nav_menu( array(
  152. 'theme_location' => 'footer',
  153. 'depth' => 1,
  154. ) );
  155. }
  156. //* Reposition Featured Images
  157. remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
  158. add_action( 'genesis_entry_header', 'genesis_do_post_image', 5 );
  159. //* Reposition Post Info Above Post Title
  160. remove_action( 'genesis_entry_header', 'genesis_post_info', 12);
  161. add_action( 'genesis_entry_header', 'genesis_post_info', 9 );
  162. //* Reposition Post Meta Below Post Title
  163. remove_action( 'genesis_entry_footer', 'genesis_post_meta');
  164. add_action( 'genesis_entry_header', 'genesis_post_meta', 12 );
  165. //* Customize the Post Info Function
  166. add_filter( 'genesis_post_info', 'captivating_post_info_filter' );
  167. function captivating_post_info_filter( $post_info ) {
  168. $post_info = '[post_date] &middot; [post_comments before="<i class="icon ion-paintbucket"></i>" zero="Leave a Comment" one="1 Comment" more="% Comments"]';
  169. return $post_info;
  170. }
  171. //* Customize the Post Meta function
  172. add_filter( 'genesis_post_meta', 'captivating_post_meta_filter' );
  173. function captivating_post_meta_filter( $post_meta ) {
  174. $post_meta = '[post_categories before="" sep="&middot;"]';
  175. return $post_meta;
  176. }
  177. //* Modify the size of the Gravatar in the entry comments
  178. add_filter( 'genesis_comment_list_args', 'captivating_comments_gravatar' );
  179. function captivating_comments_gravatar( $args ) {
  180. $args['avatar_size'] = 96;
  181. return $args;
  182. }
  183. //* Modify the size of the Gravatar in the author box
  184. add_filter( 'genesis_author_box_gravatar_size', 'captivating_author_box_gravatar' );
  185. function captivating_author_box_gravatar( $size ) {
  186. return 200;
  187. }
  188. //* Customize search form input box text
  189. add_filter( 'genesis_search_text', 'captivating_search_text' );
  190. function captivating_search_text( $text ) {
  191. return esc_attr( 'Search . . .' );
  192. }
  193. //* Remove comment form allowed tags
  194. add_filter( 'comment_form_defaults', 'captivating_remove_comment_form_allowed_tags' );
  195. function captivating_remove_comment_form_allowed_tags( $defaults ) {
  196. $defaults['comment_notes_after'] = '';
  197. return $defaults;
  198. }
  199. // Customize 'Read More' text with accessibility.
  200. add_filter( 'excerpt_more', 'captivating_read_more_link' );
  201. add_filter( 'get_the_content_more_link', 'captivating_read_more_link' );
  202. add_filter( 'the_content_more_link', 'captivating_read_more_link' );
  203. function captivating_read_more_link($more) {
  204. $new_a11y_read_more_title = sprintf( '<span class="screen-reader-text">%s %s</span>', __( 'about ', 'captivating' ), get_the_title() );
  205. return sprintf( ' ... <a href="%s" class="more-link">%s %s</a>', get_permalink(), __( 'Read More', 'captivating' ), $new_a11y_read_more_title );
  206. }
  207. //* Hooks Announcement Widget
  208. add_action( 'genesis_before', 'captivating_announcement_widget', 8 );
  209. function captivating_announcement_widget() {
  210. genesis_widget_area( 'announcement-widget', array(
  211. 'before' => '<div class="announcement-widget widget-area"><div class="wrap">',
  212. 'after' => '</div></div>',
  213. ) );
  214. }
  215. //* Hooks Widget Area Above Content
  216. add_action( 'genesis_before_footer', 'captivating_site_wide_cta', 6 );
  217. function captivating_site_wide_cta() {
  218. if ( !is_home() ){
  219. genesis_widget_area( 'site-wide-cta', array(
  220. 'before' => '<div class="site-wide-cta widget-area"><div class="wrap">',
  221. 'after' => '</div></div>',
  222. ) );
  223. }}
  224. //* Hooks Widget Area Below Footer
  225. add_action( 'genesis_before_footer', 'captivating_widget_below_footer', 12 );
  226. function captivating_widget_below_footer() {
  227. genesis_widget_area( 'widget-below-footer', array(
  228. 'before' => '<div class="widget-below-footer widget-area">',
  229. 'after' => '</div>',
  230. ) );
  231. }
  232. //* Force 12 posts to appear on all archive pages
  233. add_action('pre_get_posts', 'captivating_change_posts_per_page', 1);
  234. function captivating_change_posts_per_page( $query ) {
  235. if( ! $query->is_main_query() )
  236. return;
  237. if ( is_archive() ){
  238. $query->set( 'posts_per_page', 12); //* This changes the # of posts displayed on the category pages
  239. }
  240. }
  241. //* Load Entry Navigation
  242. add_action( 'genesis_after_entry', 'genesis_prev_next_post_nav', 9 );
  243. //* Customize the credits
  244. add_filter('genesis_footer_creds_text', 'captivating_footer_creds_text');
  245. function captivating_footer_creds_text( $creds ) {
  246. $creds = '<div class="creds">Copyright [footer_copyright] &middot; <a target="_blank" href="http://restored316designs.com/themes">captivating theme</a> by <a target="_blank" href="http://www.restored316designs.com">Restored 316</a></div>';
  247. return $creds;
  248. }
  249. //* Add Theme Support for WooCommerce
  250. add_theme_support( 'genesis-connect-woocommerce' );
  251. //* Remove Related Products
  252. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  253. //* Change number or products per row to 3
  254. add_filter('loop_shop_columns', 'loop_columns');
  255. if (!function_exists('loop_columns')) {
  256. function loop_columns() {
  257. return 3; // 3 products per row
  258. }
  259. }
  260. //* Add WooCommerce Gallery Options
  261. add_action( 'after_setup_theme', 'captivating_woo_gallery' );
  262. function captivating_woo_gallery() {
  263. //add_theme_support( 'wc-product-gallery-zoom' );
  264. add_theme_support( 'wc-product-gallery-lightbox' );
  265. add_theme_support( 'wc-product-gallery-slider' );
  266. }
  267. //* Add WP Recipe Maker Jump to Recipe
  268. add_action('genesis_entry_content', 'captivating_wprm_buttons', 1);
  269. function captivating_wprm_buttons() {
  270. if ( is_single() && ( shortcode_exists( 'wprm-recipe-jump' ) || shortcode_exists( 'wprm-recipe-print' ) ) ) {
  271. echo '<div class="wprm-buttons">';
  272. if ( shortcode_exists( 'wprm-recipe-jump' ) ) {
  273. echo do_shortcode( '[wprm-recipe-jump]' );
  274. }
  275. echo '</div>';
  276. }
  277. }