esc_html__( 'Mobile', 'blogcards' ), 'header' => esc_html__( 'Header', 'blogcards' ), ) ); } } add_action( 'after_setup_theme', 'blogcards_setup' ); /* Custom navigation /* ------------------------------------ */ if ( ! class_exists( '\Blogcards\Nav' ) ) { require_once 'functions/nav.php'; } add_action( 'wp', function() { $nav = new \Blogcards\Nav(); $nav->enqueue( [ 'script' => 'js/nav.js', 'inline' => false, ] ); $nav->init(); } ); /* Custom logo /* ------------------------------------ */ if ( ! function_exists( 'blogcards_custom_logo' ) ) { function blogcards_custom_logo() { $defaults = array( 'height' => 120, 'width' => 400, 'flex-height' => true, 'flex-width' => true, 'header-text' => array( 'site-title', 'site-description' ), ); add_theme_support( 'custom-logo', $defaults ); } } add_action( 'after_setup_theme', 'blogcards_custom_logo' ); /* Custom header /* ------------------------------------ */ if ( ! function_exists( 'blogcards_custom_header' ) ) { function blogcards_custom_header() { $args = array( 'default-image' => false, 'default-text' => false, 'width' => 1120, 'height' => 300, 'flex-width' => true, 'flex-height' => true, ); add_theme_support( 'custom-header', $args ); } } add_action( 'after_setup_theme', 'blogcards_custom_header' ); /* Custom background /* ------------------------------------ */ if ( ! function_exists( 'blogcards_custom_background' ) ) { function blogcards_custom_background() { $args = array(); add_theme_support( 'custom-background', $args ); } } add_action( 'after_setup_theme', 'blogcards_custom_background' ); /* Deregister /* ------------------------------------ */ if ( ! function_exists( 'blogcards_deregister' ) ) { function blogcards_deregister() { wp_deregister_style( 'wp-pagenavi' ); } } add_action( 'wp_enqueue_scripts', 'blogcards_deregister', 100 ); /* Register sidebars /* ------------------------------------ */ if ( ! function_exists( 'blogcards_sidebars' ) ) { function blogcards_sidebars() { if ( get_theme_mod('footer-widgets') >= '1' ) { register_sidebar(array( 'name' => esc_html__('Footer 1','blogcards'),'id' => 'footer-1', 'description' => esc_html__("Widgetized footer","blogcards"), 'before_widget' => '
','after_widget' => '
','before_title' => '

','after_title' => '

')); } if ( get_theme_mod('footer-widgets') >= '2' ) { register_sidebar(array( 'name' => esc_html__('Footer 2','blogcards'),'id' => 'footer-2', 'description' => esc_html__("Widgetized footer","blogcards"), 'before_widget' => '
','after_widget' => '
','before_title' => '

','after_title' => '

')); } if ( get_theme_mod('footer-widgets') >= '3' ) { register_sidebar(array( 'name' => esc_html__('Footer 3','blogcards'),'id' => 'footer-3', 'description' => esc_html__("Widgetized footer","blogcards"), 'before_widget' => '
','after_widget' => '
','before_title' => '

','after_title' => '

')); } if ( get_theme_mod('footer-widgets') >= '4' ) { register_sidebar(array( 'name' => esc_html__('Footer 4','blogcards'),'id' => 'footer-4', 'description' => esc_html__("Widgetized footer","blogcards"), 'before_widget' => '
','after_widget' => '
','before_title' => '

','after_title' => '

')); } } } add_action( 'widgets_init', 'blogcards_sidebars' ); /* Enqueue javascript /* ------------------------------------ */ if ( ! function_exists( 'blogcards_scripts' ) ) { function blogcards_scripts() { wp_enqueue_script( 'blogcards-slick', get_template_directory_uri() . '/js/slick.min.js', array( 'jquery' ),'', false ); if ( get_theme_mod( 'theme-toggle','on' ) == 'on' ) { wp_enqueue_script( 'blogcards-theme-toggle', get_template_directory_uri() . '/js/theme-toggle.js', array( 'jquery' ),'', true ); } wp_enqueue_script( 'blogcards-scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ),'', true ); if ( is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } } add_action( 'wp_enqueue_scripts', 'blogcards_scripts' ); /* Enqueue css /* ------------------------------------ */ if ( ! function_exists( 'blogcards_styles' ) ) { function blogcards_styles() { wp_enqueue_style( 'blogcards-style', get_stylesheet_uri() ); wp_enqueue_style( 'blogcards-responsive', get_template_directory_uri().'/responsive.css' ); if ( ( get_theme_mod( 'dark-theme','off' ) == 'on' ) || ( get_theme_mod( 'theme-toggle','on' ) == 'on' ) ) { wp_enqueue_style( 'blogcards-dark', get_template_directory_uri().'/dark.css' ); } wp_enqueue_style( 'blogcards-font-awesome', get_template_directory_uri().'/fonts/all.min.css' ); } } add_action( 'wp_enqueue_scripts', 'blogcards_styles' ); /* ------------------------------------------------------------------------- * * Template functions /* ------------------------------------------------------------------------- */ /* Social links /* ------------------------------------ */ if ( ! function_exists( 'blogcards_social_links' ) ) { function blogcards_social_links() { if ( !get_theme_mod('social-links') =='' ) { $links = get_theme_mod('social-links', array()); if ( !empty( $links ) ) { echo ''; } } } } /* Site name/logo /* ------------------------------------ */ if ( ! function_exists( 'blogcards_site_title' ) ) { function blogcards_site_title() { $custom_logo_id = get_theme_mod( 'custom_logo' ); $logo = wp_get_attachment_image_src( $custom_logo_id , 'full' ); // Text or image? if ( has_custom_logo() && $logo !== false ) { $logo = ''.esc_attr( get_bloginfo('name')).''; } else { $logo = esc_html( get_bloginfo('name') ); } $link = ''.$logo.''; if ( is_front_page() || is_home() ) { $sitename = '

'.$link.'

'."\n"; } else { $sitename = '

'.$link.'

'."\n"; } return $sitename; } } /* Blog title /* ------------------------------------ */ if ( ! function_exists( 'blogcards_blog_title' ) ) { function blogcards_blog_title() { global $post; $heading = esc_html( get_theme_mod('blog-heading') ); $subheading = esc_html( get_theme_mod('blog-subheading') ); if($heading) { $title = $heading; } else { $title = esc_html( get_bloginfo('name') ); } if($subheading) { $title = $title.' '.$subheading.''; } return $title; } } /* Related posts /* ------------------------------------ */ if ( ! function_exists( 'blogcards_related_posts' ) ) { function blogcards_related_posts() { wp_reset_postdata(); global $post; // Define shared post arguments $args = array( 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'rand', 'post__not_in' => array($post->ID), 'posts_per_page' => 2 ); // Related by categories if ( get_theme_mod( 'related-posts','categories' ) == 'categories' ) { $cats = get_post_meta($post->ID, 'related-cat', true); if ( !$cats ) { $cats = wp_get_post_categories($post->ID, array('fields'=>'ids')); $args['category__in'] = $cats; } else { $args['cat'] = $cats; } } // Related by tags if ( get_theme_mod( 'related-posts','categories' ) == 'tags' ) { $tags = get_post_meta($post->ID, 'related-tag', true); if ( !$tags ) { $tags = wp_get_post_tags($post->ID, array('fields'=>'ids')); $args['tag__in'] = $tags; } else { $args['tag_slug__in'] = explode(',', $tags); } if ( !$tags ) { $break = true; } } $query = !isset($break)?new WP_Query($args):new WP_Query; return $query; } } /* Get featured post ids /* ------------------------------------ */ if ( ! function_exists( 'blogcards_get_featured_post_ids' ) ) { function blogcards_get_featured_post_ids() { $args = array( 'category' => absint( get_theme_mod('featured-category','') ), 'numberposts' => absint( get_theme_mod('featured-posts-count','6')), ); $posts = get_posts($args); if ( !$posts ) return false; foreach ( $posts as $post ) $ids[] = $post->ID; return $ids; } } /* ------------------------------------------------------------------------- * * Filters /* ------------------------------------------------------------------------- */ /* Body class /* ------------------------------------ */ if ( ! function_exists( 'blogcards_body_class' ) ) { function blogcards_body_class( $classes ) { if ( get_theme_mod( 'boxed','off' ) != 'on' ) { $classes[] = 'full-width'; } if ( get_theme_mod( 'boxed','off' ) == 'on' ) { $classes[] = 'boxed'; } if ( has_nav_menu( 'mobile' ) ) { $classes[] = 'mobile-menu'; } if ( get_theme_mod( 'dark-theme' ,'off' ) == 'on' ) { $classes[] = 'dark'; } if ( get_theme_mod( 'invert-logo' ,'on' ) == 'on' ) { $classes[] = 'invert-dark-logo'; } if (! ( is_user_logged_in() ) ) { $classes[] = 'logged-out'; } return $classes; } } add_filter( 'body_class', 'blogcards_body_class' ); /* Excerpt ending /* ------------------------------------ */ if ( ! function_exists( 'blogcards_excerpt_more' ) ) { function blogcards_excerpt_more( $more ) { if ( is_admin() ) { return $more; } return '...'; } } add_filter( 'excerpt_more', 'blogcards_excerpt_more' ); /* Excerpt length /* ------------------------------------ */ if ( ! function_exists( 'blogcards_excerpt_length' ) ) { function blogcards_excerpt_length( $length ) { if ( is_admin() ) { return $length; } $new_length = $length; $custom_length = get_theme_mod( 'excerpt-length', '20' ); if ( absint( $custom_length ) > 0 ) { $new_length = absint( $custom_length ); } return $new_length; } } add_filter( 'excerpt_length', 'blogcards_excerpt_length', 999 ); /* Comments avatar size /* ------------------------------------ */ if ( ! function_exists( 'blogcards_comments_avatar_size' ) ) { function blogcards_comments_avatar_size( $args ) { $args['avatar_size'] = 64; return $args; } } add_filter( 'wp_list_comments_args', 'blogcards_comments_avatar_size' ); /* ------------------------------------------------------------------------- * * Actions /* ------------------------------------------------------------------------- */ /* Include or exclude featured articles in loop /* ------------------------------------ */ if ( ! function_exists( 'blogcards_pre_get_posts' ) ) { function blogcards_pre_get_posts( $query ) { // Are we on main query ? if ( !$query->is_main_query() ) return; if ( $query->is_home() ) { // Featured posts enabled if ( get_theme_mod('featured-posts-count','6') != '0' ) { // Get featured post ids $featured_post_ids = blogcards_get_featured_post_ids(); // Exclude posts if ( $featured_post_ids && get_theme_mod('featured-posts-include','off') =='on' ) $query->set('post__not_in', $featured_post_ids); } } } } add_action( 'pre_get_posts', 'blogcards_pre_get_posts' ); /* Script for no-js / js class /* ------------------------------------ */ if ( ! function_exists( 'blogcards_html_js_class' ) ) { function blogcards_html_js_class () { echo ''. "\n"; } } add_action( 'wp_head', 'blogcards_html_js_class', 1 ); /* Admin panel css /* ------------------------------------ */ if ( ! function_exists( 'blogcards_admin_panel_css' ) ) { function blogcards_admin_panel_css() { global $pagenow; if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { echo ''; } } } add_action( 'admin_head', 'blogcards_admin_panel_css' ); /* TGM plugin activation /* ------------------------------------ */ if ( ! function_exists( 'blogcards_plugins' ) ) { function blogcards_plugins() { if ( get_theme_mod('recommended-plugins','on') =='on' ) { // Add the following plugins $plugins = array( array( 'name' => esc_html__( 'Alx Extensions', 'blogcards' ), 'slug' => 'alx-extensions', ), array( 'name' => esc_html__( 'Meta Box', 'blogcards' ), 'slug' => 'meta-box', ), array( 'name' => esc_html__( 'Regenerate Thumbnails', 'blogcards' ), 'slug' => 'regenerate-thumbnails', ), array( 'name' => esc_html__( 'WP-PageNavi', 'blogcards' ), 'slug' => 'wp-pagenavi', ) ); tgmpa( $plugins ); } } } add_action( 'tgmpa_register', 'blogcards_plugins' ); /* WooCommerce basic support /* ------------------------------------ */ function blogcards_wc_wrapper_start() { echo '
'; } function blogcards_wc_wrapper_end() { echo '
'; } remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); add_action('woocommerce_before_main_content', 'blogcards_wc_wrapper_start', 10); add_action('woocommerce_after_main_content', 'blogcards_wc_wrapper_end', 10); /* Accessibility IE11 fix - https://git.io/vWdr2 /* ------------------------------------ */ function blogcards_skip_link_focus_fix() { ?>