functions.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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.1' );
  27. //* Adds Gutenberg opt-in features and styling.
  28. add_action( 'after_setup_theme', 'captivating_gutenberg_support' );
  29. function captivating_gutenberg_support() {
  30. require_once get_stylesheet_directory() . '/lib/gutenberg/init.php';
  31. }
  32. //* Loads Responsive Menu, Google Fonts, Icons, and other scripts
  33. add_action( 'wp_enqueue_scripts', 'captivating_enqueue_scripts' );
  34. function captivating_enqueue_scripts() {
  35. 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() );
  36. wp_enqueue_style( 'ionicons', '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', array(), CHILD_THEME_VERSION );
  37. wp_enqueue_style( 'dashicons' );
  38. wp_enqueue_script( 'captivating-global-script', get_bloginfo( 'stylesheet_directory' ) . '/js/global.js', array( 'jquery' ), '1.0.0' );
  39. wp_enqueue_script( 'match-height', get_stylesheet_directory_uri() . '/js/jquery.matchHeight-min.js', array( 'jquery' ), '1.0.0', true );
  40. wp_enqueue_script( 'match-height-init', get_stylesheet_directory_uri() . '/js/matchheight-init.js', array( 'match-height' ), '1.0.0', true );
  41. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
  42. wp_enqueue_script( 'captivating-responsive-menu', get_stylesheet_directory_uri() . "/js/responsive-menus{$suffix}.js", array( 'jquery' ), CHILD_THEME_VERSION, true );
  43. wp_localize_script(
  44. 'captivating-responsive-menu',
  45. 'genesis_responsive_menu',
  46. captivating_responsive_menu_settings()
  47. );
  48. }
  49. // Define our responsive menu settings.
  50. function captivating_responsive_menu_settings() {
  51. $settings = array(
  52. 'mainMenu' => __( 'Menu', 'captivating' ),
  53. 'menuIconClass' => 'dashicons-before dashicons-menu',
  54. 'subMenu' => __( 'Submenu', 'captivating' ),
  55. 'subMenuIconsClass' => 'dashicons-before dashicons-arrow-down-alt2',
  56. 'menuClasses' => array(
  57. 'combine' => array(
  58. '.nav-header',
  59. '.nav-header-left',
  60. '.nav-header-right',
  61. '.nav-secondary',
  62. '.nav-primary',
  63. ),
  64. 'others' => array(
  65. '.nav-footer',
  66. ),
  67. ),
  68. );
  69. return $settings;
  70. }
  71. //* Add support for footer menu & rename menus
  72. add_theme_support ( 'genesis-menus' , array (
  73. 'primary' => 'Above Header Menu',
  74. 'secondary' => 'Below Header Menu',
  75. 'header-left' => 'Header Left',
  76. 'header-right' => 'Header Right',
  77. 'footer' => 'Footer Menu'
  78. ) );
  79. //* Add HTML5 markup structure
  80. add_theme_support( 'html5' );
  81. //* Add new featured image sizes
  82. add_image_size( 'square-entry-image', 400, 400, TRUE );
  83. add_image_size( 'vertical-entry-image', 400, 600, TRUE );
  84. add_image_size( 'horizontal-entry-image', 820, 550, TRUE );
  85. //* Add support for 3-column footer widgets
  86. add_theme_support( 'genesis-footer-widgets', 3 );
  87. //* Add viewport meta tag for mobile browsers
  88. add_theme_support( 'genesis-responsive-viewport' );
  89. //* Add support for custom background
  90. add_theme_support( 'custom-background', array(
  91. 'default-color' => 'FFFFFF',
  92. ));
  93. //* Add support for after entry widget
  94. add_theme_support( 'genesis-after-entry-widget-area' );
  95. //* Add support for custom header
  96. add_theme_support( 'custom-header', array(
  97. 'width' => 2000,
  98. 'height' => 1562,
  99. 'header-selector' => '.site-title a',
  100. 'header-text' => false,
  101. ) );
  102. //* Remove the site description
  103. remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
  104. //* Unregister layout settings
  105. genesis_unregister_layout( 'content-sidebar-sidebar' );
  106. genesis_unregister_layout( 'sidebar-content-sidebar' );
  107. genesis_unregister_layout( 'sidebar-sidebar-content' );
  108. //* Unregister secondary sidebar
  109. unregister_sidebar( 'sidebar-alt' );
  110. //* Reposition the primary navigation menu
  111. remove_action( 'genesis_after_header', 'genesis_do_nav' );
  112. add_action( 'genesis_before_header', 'genesis_do_nav', 7 );
  113. //* Add search form to navigation
  114. add_filter( 'wp_nav_menu_items', 'captivating_primary_nav_extras', 10, 2 );
  115. function captivating_primary_nav_extras( $menu, $args ) {
  116. if ( 'primary' !== $args->theme_location ) {
  117. return $menu;
  118. }
  119. ob_start();
  120. get_search_form();
  121. $search = ob_get_clean();
  122. $menu .= '<li class="right search">' . $search . '</li>';
  123. return $menu;
  124. }
  125. //* Add widget to primary navigation
  126. add_filter( 'genesis_nav_items', 'captivating_social_icons', 10, 2 );
  127. add_filter( 'wp_nav_menu_items', 'captivating_social_icons', 10, 2 );
  128. function captivating_social_icons($menu, $args) {
  129. $args = (array)$args;
  130. if ( 'primary' !== $args['theme_location'] )
  131. return $menu;
  132. ob_start();
  133. genesis_widget_area('nav-social-menu');
  134. $social = ob_get_clean();
  135. return $menu . $social;
  136. }
  137. //* Hook menu to left of Logo
  138. add_action( 'genesis_header', 'captivating_header_left_menu', 6 );
  139. function captivating_header_left_menu() {
  140. genesis_nav_menu( array(
  141. 'theme_location' => 'header-left',
  142. 'depth' => 2,
  143. ) );
  144. }
  145. //* Hook menu to right of Logo
  146. add_action( 'genesis_header', 'captivating_header_right_menu', 9 );
  147. function captivating_header_right_menu() {
  148. genesis_nav_menu( array(
  149. 'theme_location' => 'header-right',
  150. 'depth' => 2,
  151. ) );
  152. }
  153. //* Hook menu in footer
  154. add_action( 'genesis_before_footer', 'captivating_footer_menu', 7 );
  155. function captivating_footer_menu() {
  156. genesis_nav_menu( array(
  157. 'theme_location' => 'footer',
  158. 'depth' => 1,
  159. ) );
  160. }
  161. //* Reposition Featured Images
  162. remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
  163. add_action( 'genesis_entry_header', 'genesis_do_post_image', 5 );
  164. //* Reposition Post Info Above Post Title
  165. remove_action( 'genesis_entry_header', 'genesis_post_info', 12);
  166. add_action( 'genesis_entry_header', 'genesis_post_info', 9 );
  167. //* Reposition Post Meta Below Post Title
  168. remove_action( 'genesis_entry_footer', 'genesis_post_meta');
  169. add_action( 'genesis_entry_header', 'genesis_post_meta', 12 );
  170. //* Customize the Post Info Function
  171. add_filter( 'genesis_post_info', 'captivating_post_info_filter' );
  172. function captivating_post_info_filter( $post_info ) {
  173. $post_info = '[post_date] &middot; [post_comments before="<i class="icon ion-paintbucket"></i>" zero="Leave a Comment" one="1 Comment" more="% Comments"]';
  174. return $post_info;
  175. }
  176. //* Customize the Post Meta function
  177. add_filter( 'genesis_post_meta', 'captivating_post_meta_filter' );
  178. function captivating_post_meta_filter( $post_meta ) {
  179. $post_meta = '[post_categories before="" sep="&middot;"]';
  180. return $post_meta;
  181. }
  182. //* Modify the size of the Gravatar in the entry comments
  183. add_filter( 'genesis_comment_list_args', 'captivating_comments_gravatar' );
  184. function captivating_comments_gravatar( $args ) {
  185. $args['avatar_size'] = 96;
  186. return $args;
  187. }
  188. //* Modify the size of the Gravatar in the author box
  189. add_filter( 'genesis_author_box_gravatar_size', 'captivating_author_box_gravatar' );
  190. function captivating_author_box_gravatar( $size ) {
  191. return 200;
  192. }
  193. //* Customize search form input box text
  194. add_filter( 'genesis_search_text', 'captivating_search_text' );
  195. function captivating_search_text( $text ) {
  196. return esc_attr( 'Search . . .' );
  197. }
  198. //* Remove comment form allowed tags
  199. add_filter( 'comment_form_defaults', 'captivating_remove_comment_form_allowed_tags' );
  200. function captivating_remove_comment_form_allowed_tags( $defaults ) {
  201. $defaults['comment_notes_after'] = '';
  202. return $defaults;
  203. }
  204. // Customize 'Read More' text with accessibility.
  205. add_filter( 'excerpt_more', 'captivating_read_more_link' );
  206. add_filter( 'get_the_content_more_link', 'captivating_read_more_link' );
  207. add_filter( 'the_content_more_link', 'captivating_read_more_link' );
  208. function captivating_read_more_link($more) {
  209. $new_a11y_read_more_title = sprintf( '<span class="screen-reader-text">%s %s</span>', __( 'about ', 'captivating' ), get_the_title() );
  210. return sprintf( ' ... <a href="%s" class="more-link">%s %s</a>', get_permalink(), __( 'Read More', 'captivating' ), $new_a11y_read_more_title );
  211. }
  212. //* Hooks Announcement Widget
  213. add_action( 'genesis_before', 'captivating_announcement_widget', 8 );
  214. function captivating_announcement_widget() {
  215. genesis_widget_area( 'announcement-widget', array(
  216. 'before' => '<div class="announcement-widget widget-area"><div class="wrap">',
  217. 'after' => '</div></div>',
  218. ) );
  219. }
  220. //* Hooks Widget Area Above Content
  221. add_action( 'genesis_before_footer', 'captivating_site_wide_cta', 6 );
  222. function captivating_site_wide_cta() {
  223. if ( !is_home() ){
  224. genesis_widget_area( 'site-wide-cta', array(
  225. 'before' => '<div class="site-wide-cta widget-area"><div class="wrap">',
  226. 'after' => '</div></div>',
  227. ) );
  228. }}
  229. //* Hooks Widget Area Below Footer
  230. add_action( 'genesis_before_footer', 'captivating_widget_below_footer', 12 );
  231. function captivating_widget_below_footer() {
  232. genesis_widget_area( 'widget-below-footer', array(
  233. 'before' => '<div class="widget-below-footer widget-area">',
  234. 'after' => '</div>',
  235. ) );
  236. }
  237. //* Force 12 posts to appear on all archive pages
  238. add_action('pre_get_posts', 'captivating_change_posts_per_page', 1);
  239. function captivating_change_posts_per_page( $query ) {
  240. if( ! $query->is_main_query() )
  241. return;
  242. if ( is_archive() ){
  243. $query->set( 'posts_per_page', 12); //* This changes the # of posts displayed on the category pages
  244. }
  245. }
  246. //* Load Entry Navigation
  247. add_action( 'genesis_after_entry', 'genesis_prev_next_post_nav', 9 );
  248. //* Customize the credits
  249. add_filter('genesis_pre_get_option_footer_text', 'captivating_footer_creds_text');
  250. function captivating_footer_creds_text( $creds ) {
  251. $creds = '<div class="creds">Copyright [footer_copyright] &middot; Cottage at the Crossroads</div>';
  252. return $creds;
  253. }
  254. //* Add Theme Support for WooCommerce
  255. add_theme_support( 'genesis-connect-woocommerce' );
  256. //* Remove Related Products
  257. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  258. //* Change number or products per row to 3
  259. add_filter('loop_shop_columns', 'loop_columns');
  260. if (!function_exists('loop_columns')) {
  261. function loop_columns() {
  262. return 3; // 3 products per row
  263. }
  264. }
  265. //* Add WooCommerce Gallery Options
  266. add_action( 'after_setup_theme', 'captivating_woo_gallery' );
  267. function captivating_woo_gallery() {
  268. //add_theme_support( 'wc-product-gallery-zoom' );
  269. add_theme_support( 'wc-product-gallery-lightbox' );
  270. add_theme_support( 'wc-product-gallery-slider' );
  271. }
  272. //* Add WP Recipe Maker Jump to Recipe
  273. add_action('genesis_entry_content', 'captivating_wprm_buttons', 1);
  274. function captivating_wprm_buttons() {
  275. if ( is_single() && ( shortcode_exists( 'wprm-recipe-jump' ) || shortcode_exists( 'wprm-recipe-print' ) ) ) {
  276. echo '<div class="wprm-buttons">';
  277. if ( shortcode_exists( 'wprm-recipe-jump' ) ) {
  278. echo do_shortcode( '[wprm-recipe-jump]' );
  279. }
  280. echo '</div>';
  281. }
  282. }
  283. //* ##################################################################### *//
  284. //* Add Amazon statement after after 2nd paragraph of single post content.
  285. add_filter( 'the_content', 'prefix_insert_post_ads' );
  286. function prefix_insert_post_ads( $content ) {
  287. $ad_code = '<div class="aws_statement"><p>This post may contain Amazon or other affiliate links. As an Amazon associate, I earn from qualifying purchases. If you purchase anything through any affiliate link, I may earn a small commission at no extra charge to you. All opinions are my own.</p></div>';
  288. if ( is_single() && ! is_admin() ) {
  289. return prefix_insert_after_paragraph( $ad_code, 2, $content );
  290. }
  291. return $content;
  292. }
  293. function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
  294. $closing_p = '</p>';
  295. $paragraphs = explode( $closing_p, $content );
  296. foreach ($paragraphs as $index => $paragraph) {
  297. if ( trim( $paragraph ) ) {
  298. $paragraphs[$index] .= $closing_p;
  299. }
  300. if ( $paragraph_id == $index + 1 ) {
  301. $paragraphs[$index] .= $insertion;
  302. }
  303. }
  304. return implode( '', $paragraphs );
  305. }