/** * Functions which enhance the theme by hooking into WordPress * * @package fabulist */ if( ! function_exists( 'fabulist_check_enable_status' ) ): /** * Adds custom classes to the array of body classes. * * @param array $classes Classes for the body element. * @return array */ function fabulist_body_classes( $classes ) { // Adds a class of hfeed to non-singular pages. if ( ! is_singular() ) { $classes[] = 'hfeed'; } $site_layout = fabulist_theme_option( 'site_layout' ); $classes[] = esc_attr( $site_layout ); $classes[] = 'featured-categories-disabled'; $sidebar_layout = fabulist_sidebar_layout(); if ( is_404() ) $sidebar_layout = 'no-sidebar'; $classes[] = esc_attr( $sidebar_layout ); return $classes; } endif; add_filter( 'body_class', 'fabulist_body_classes' ); /** * Add customizer defaults. */ require get_template_directory() . '/inc/customizer/default.php'; /** * Add options. */ require get_template_directory() . '/inc/options.php'; if( ! function_exists( 'fabulist_theme_option' ) ): /** * Merge values from default options array and values from customizer * * @return customizer value */ function fabulist_theme_option( $controler, $default = null ) { if ( empty( $controler ) ) return; $fabulist_default_options = fabulist_get_default_theme_options(); $output = wp_parse_args( get_theme_mod( 'fabulist_theme_options' ), $fabulist_default_options ) ; return ! empty( $output[$controler] ) ? $output[$controler] : $default; } endif; if( ! function_exists( 'fabulist_check_enable_status' ) ): /** * Check status of content. * * @return boolean */ function fabulist_check_enable_status( $content_enable = true, $entire_site = false ){ // Content status. $content_status = fabulist_theme_option( $content_enable ); $entire_site = fabulist_theme_option( $entire_site ); if ( $content_status && $entire_site ) : return true; elseif ( $content_status && ! $entire_site ) : if ( is_home() && is_front_page() ) return true; else return false; else : return false; endif; } endif; add_filter( 'fabulist_section_status', 'fabulist_check_enable_status', 10, 2 ); /** * Add construct hooks. */ require get_template_directory() . '/inc/construct.php'; /** * Add sanitization functions. */ require get_template_directory() . '/inc/sanitize.php'; /** * Add template hooks. */ require get_template_directory() . '/inc/template-hooks/template-hooks.php'; /** * Add metabox. */ require get_template_directory() . '/inc/metabox.php'; if ( ! function_exists( 'fabulist_excerpt_length' ) ) : /** * excerpt length * * @return excerpt length value */ function fabulist_excerpt_length( $length ){ if ( is_admin() ) { return $length; } $length = fabulist_theme_option( 'excerpt_count', 25 ); return absint( $length ); } endif; add_filter( 'excerpt_length', 'fabulist_excerpt_length', 999 ); if ( ! function_exists( 'fabulist_pagination' ) ) : /** * blog/archive pagination. * * @return pagination type value */ function fabulist_pagination() { $pagination = fabulist_theme_option( 'pagination_type' ); if ( $pagination == 'default' ) : the_posts_navigation(); elseif ( in_array( $pagination, array( 'infinite', 'numeric', 'click' ) ) ) : the_posts_pagination( array( 'mid_size' => 4, 'prev_text' => fabulist_get_svg( array( 'icon' => 'angle-left' ) ), 'next_text' => fabulist_get_svg( array( 'icon' => 'angle-right' ) ), ) ); endif; } endif; add_action( 'fabulist_pagination_action', 'fabulist_pagination', 10 ); if ( ! function_exists( 'fabulist_sidebar_layout' ) ) : /** * sidebar layout * * @return sidebar layout */ function fabulist_sidebar_layout(){ $sidebar = 'sidebar-1'; if ( is_home() && is_front_page() ) return 'no-sidebar'; if ( is_singular() ) { $sidebar = get_post_meta( get_the_ID(), 'fabulist-selected-sidebar', true ); $sidebar = ! empty( $sidebar ) ? $sidebar : 'sidebar-1'; } if ( is_active_sidebar( $sidebar ) ) : if ( is_single() ) : $post_layout = get_post_meta( get_the_ID(), 'fabulist-sidebar-position', true ); if ( ! empty( $post_layout ) ) { return $post_layout; } else { return fabulist_theme_option( 'sidebar_single_layout' ); } elseif ( is_page() ) : $page_layout = get_post_meta( get_the_ID(), 'fabulist-sidebar-position', true ); if ( ! empty( $page_layout ) ) { return $page_layout; } else { return fabulist_theme_option( 'sidebar_page_layout' ); } else : return fabulist_theme_option( 'sidebar_layout' ); endif; else : return 'no-sidebar'; endif; } endif; /** * Add SVG definitions to the footer. */ function fabulist_include_svg_icons() { // Define SVG sprite file. $svg_icons = get_template_directory() . '/assets/svg-icons.svg'; // If it exists, include it. if ( file_exists( $svg_icons ) ) { require_once( $svg_icons ); } } add_action( 'wp_footer', 'fabulist_include_svg_icons', 9999 ); /** * Return SVG markup. * * @param array $args { * Parameters needed to display an SVG. * * @type string $icon Required SVG icon filename. * @type string $title Optional SVG title. * @type string $desc Optional SVG description. * } * @return string SVG markup. */ function fabulist_get_svg( $args = array() ) { // Make sure $args are an array. if ( empty( $args ) ) { return esc_html__( 'Please define default parameters in the form of an array.', 'fabulist' ); } // Define an icon. if ( false === array_key_exists( 'icon', $args ) ) { return esc_html__( 'Please define an SVG icon filename.', 'fabulist' ); } // Set defaults. $defaults = array( 'icon' => '', 'title' => '', 'desc' => '', 'class' => '', 'fallback' => false, ); // Parse args. $args = wp_parse_args( $args, $defaults ); // Set aria hidden. $aria_hidden = ' aria-hidden="true"'; // Set ARIA. $aria_labelledby = ''; /* * Shark Themes doesn't use the SVG title or description attributes; non-decorative icons are described with .screen-reader-text. * * However, child themes can use the title and description to add information to non-decorative SVG icons to improve accessibility. * * Example 1 with title: