ID, 'benevolent_sidebar_layout', true ); if( $sidebar_layout == 'no-sidebar' ) $classes[] = 'full-width'; } if( get_theme_mod( 'benevolent_ed_slider' ) ){ $classes[] = 'has-slider'; } return $classes; } add_filter( 'body_class', 'benevolent_body_classes' ); /** * Custom Bread Crumb * * @link http://www.qualitytuts.com/wordpress-custom-breadcrumbs-without-plugin/ */ function benevolent_breadcrumbs_cb() { global $post; $post_page = get_option( 'page_for_posts' ); //The ID of the page that displays posts. $show_front = get_option( 'show_on_front' ); //What to show on the front page $showCurrent = get_theme_mod( 'benevolent_ed_current', '1' ); // 1 - show current post/page title in breadcrumbs, 0 - don't show $delimiter = get_theme_mod( 'benevolent_breadcrumb_separator', __( '>', 'benevolent' ) ); // delimiter between crumbs $home = get_theme_mod( 'benevolent_breadcrumb_home_text', __( 'Home', 'benevolent' ) ); // text for the 'Home' link $before = ''; // tag before the current crumb $after = ''; // tag after the current crumb $depth = 1; echo '
' . esc_html( $home ) . '' . $delimiter . ''; if( is_home() && ! is_front_page() ){ $depth = 2; if( $showCurrent ) echo $before . '' . esc_html( single_post_title( '', false ) ) .''. $after; }elseif( is_category() ){ $depth = 2; $thisCat = get_category( get_query_var( 'cat' ), false ); if( $show_front === 'page' && $post_page ){ //If static blog post page is set $p = get_post( $post_page ); echo '' . esc_html( $p->post_title ) . '' . $delimiter . ''; $depth ++; } if ( $thisCat->parent != 0 ) { $parent_categories = get_category_parents( $thisCat->parent, false, ',' ); $parent_categories = explode( ',', $parent_categories ); foreach ( $parent_categories as $parent_term ) { $parent_obj = get_term_by( 'name', $parent_term, 'category' ); if( is_object( $parent_obj ) ){ $term_url = get_term_link( $parent_obj->term_id ); $term_name = $parent_obj->name; echo '' . esc_html( $term_name ) . '' . $delimiter . ''; $depth ++; } } } if( $showCurrent ) echo $before . '' . esc_html( single_cat_title( '', false ) ) . '' . $after; }elseif( is_tag() ){ $queried_object = get_queried_object(); $depth = 2; if( $showCurrent ) echo $before . '' . esc_html( single_tag_title( '', false ) ) .''. $after; }elseif( is_author() ){ $depth = 2; global $author; $userdata = get_userdata( $author ); if( $showCurrent ) echo $before . '' . esc_html( $userdata->display_name ) .''. $after; }elseif( is_day() ){ $depth = 2; echo '' . esc_html( get_the_time( __( 'Y', 'benevolent' ) ) ) . '' . $delimiter . ''; $depth ++; echo '' . esc_html( get_the_time( __( 'F', 'benevolent' ) ) ) . '' . $delimiter . ''; $depth ++; if( $showCurrent ) echo $before .''. esc_html( get_the_time( __( 'd', 'benevolent' ) ) ) .''. $after; }elseif( is_month() ){ $depth = 2; echo '' . esc_html( get_the_time( __( 'Y', 'benevolent' ) ) ) . '' . $delimiter . ''; $depth++; if( $showCurrent ) echo $before .''. esc_html( get_the_time( __( 'F', 'benevolent' ) ) ) .''. $after; }elseif( is_year() ){ $depth = 2; if( $showCurrent ) echo $before .''. esc_html( get_the_time( __( 'Y', 'benevolent' ) ) ) .''. $after; }elseif( is_single() && !is_attachment() ) { //For Post $cat_object = get_the_category(); $potential_parent = 0; $depth = 2; if( $show_front === 'page' && $post_page ){ //If static blog post page is set $p = get_post( $post_page ); echo '' . esc_html( $p->post_title ) . '' . $delimiter . ''; $depth++; } if( is_array( $cat_object ) ){ //Getting category hierarchy if any //Now try to find the deepest term of those that we know of $use_term = key( $cat_object ); foreach( $cat_object as $key => $object ){ //Can't use the next($cat_object) trick since order is unknown if( $object->parent > 0 && ( $potential_parent === 0 || $object->parent === $potential_parent ) ){ $use_term = $key; $potential_parent = $object->term_id; } } $cat = $cat_object[$use_term]; $cats = get_category_parents( $cat, false, ',' ); $cats = explode( ',', $cats ); foreach ( $cats as $cat ) { $cat_obj = get_term_by( 'name', $cat, 'category' ); if( is_object( $cat_obj ) ){ $term_url = get_term_link( $cat_obj->term_id ); $term_name = $cat_obj->name; echo '' . esc_html( $term_name ) . '' . $delimiter . ''; $depth ++; } } } if ( $showCurrent ) echo $before .''. esc_html( get_the_title() ) .''. $after; }elseif( is_page() ){ $depth = 2; if( $post->post_parent ){ global $post; $depth = 2; $parent_id = $post->post_parent; $breadcrumbs = array(); while( $parent_id ){ $current_page = get_post( $parent_id ); $breadcrumbs[] = $current_page->ID; $parent_id = $current_page->post_parent; } $breadcrumbs = array_reverse( $breadcrumbs ); for ( $i = 0; $i < count( $breadcrumbs); $i++ ){ echo '' . esc_html( get_the_title( $breadcrumbs[$i] ) ) . ''; if ( $i != count( $breadcrumbs ) - 1 ) echo ' ' . esc_html( $delimiter ) . ' '; $depth++; } if ( $showCurrent ) echo ' ' . esc_html( $delimiter ) . ' ' . $before .''. esc_html( get_the_title() ) .''. $after; }else{ if ( $showCurrent ) echo $before .''. esc_html( get_the_title() ) .''. $after; } }elseif( is_search() ){ $depth = 2; if( $showCurrent ) echo $before .''. esc_html__( 'Search Results for "', 'benevolent' ) . esc_html( get_search_query() ) . esc_html__( '"', 'benevolent' ) .''. $after; }elseif( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { $depth = 2; $post_type = get_post_type_object(get_post_type()); if( get_query_var('paged') ){ echo '' . esc_html( $post_type->label ) . ''; echo ' ' . $delimiter . ' ' . $before . sprintf( __('Page %s', 'benevolent'), get_query_var('paged') ) . $after; }elseif( is_archive() ){ echo $before .''. esc_html( $post_type->label ) .''. $after; }else{ echo $before .''. esc_html( $post_type->label ) .''. $after; } }elseif( is_attachment() ){ $depth = 2; $parent = get_post( $post->post_parent ); $cat = get_the_category( $parent->ID ); if( $cat ){ $cat = $cat[0]; echo get_category_parents( $cat, TRUE, ' ' . $delimiter . ' '); echo '' . esc_html( $parent->post_title ) . '' . ' ' . $delimiter . ''; } if( $showCurrent ) echo $before .''. esc_html( get_the_title() ) .''. $after; }elseif ( is_404() ){ if( $showCurrent ) echo $before . esc_html__( '404 Error - Page not Found', 'benevolent' ) . $after; } if( get_query_var('paged') ) echo __( ' (Page', 'benevolent' ) . ' ' . get_query_var('paged') . __( ')', 'benevolent' ); echo '
'; } // end benevolent_breadcrumbs() add_action( 'benevolent_breadcrumbs', 'benevolent_breadcrumbs_cb' ); /** * Social Links Callback */ function benevolent_social_links_cb(){ $facebook = get_theme_mod( 'benevolent_facebook' ); $twitter = get_theme_mod( 'benevolent_twitter' ); $pinterest = get_theme_mod( 'benevolent_pinterest' ); $linkedin = get_theme_mod( 'benevolent_linkedin' ); $gplus = get_theme_mod( 'benevolent_gplus' ); $instagram = get_theme_mod( 'benevolent_instagram' ); $youtube = get_theme_mod( 'benevolent_youtube' ); if( $facebook || $twitter || $pinterest || $linkedin || $gplus || $instagram || $youtube ){ ?> < id="comment-">
$add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
array( 'class' => 'intro', 'id' => 'intro' ), 'community-section' => array( 'class' => 'our-community', 'id' => 'community' ), 'stats-section' => array( 'class' => 'stats', 'id' => 'stats' ), 'blog-section' => array( 'class' => 'blog-section', 'id' => 'blog' ), 'sponsor-section' => array( 'class' => 'sponsors', 'id' => 'sponsor' ) ); $enabled_section = array(); foreach ( $sections as $section ) { if ( esc_attr( get_theme_mod( 'benevolent_ed_' . $section['id'] . '_section' ) ) == 1 ){ $enabled_section[] = array( 'id' => $section['id'], 'class' => $section['class'] ); } } return $enabled_section; } /** * Callback for Banner Slider */ function benevolent_slider_cb(){ $slider_caption = get_theme_mod( 'benevolent_slider_caption', '1' ); $slider_readmore = get_theme_mod( 'benevolent_slider_readmore', __( 'Learn More', 'benevolent' ) ); $slider_cat = get_theme_mod( 'benevolent_slider_cat' ); if( $slider_cat ){ $slider_qry = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'cat' => $slider_cat, 'ignore_sticky_posts' => true ) ); if( $slider_qry->have_posts() ){ echo ''; wp_reset_postdata(); } } } add_action( 'benevolent_slider', 'benevolent_slider_cb' ); /** * Callback Function for Promotional Block */ function benevolent_promotional_cb(){ $ed_promotional_section = get_theme_mod( 'benevolent_ed_promotional_section' ); $promotional_section_title = get_theme_mod( 'benevolent_promotional_section_title' ); $promotional_button_text = get_theme_mod( 'benevolent_promotional_button_text' ); $promotional_button_url = get_theme_mod( 'benevolent_promotional_button_url' ); $promotional_section_bg = get_theme_mod( 'benevolent_promotional_section_bg' ); if( $ed_promotional_section ){ ?>
>
' . esc_html( $promotional_section_title ) . ''; if( $promotional_button_url && $promotional_button_text ) echo '' . esc_html( $promotional_button_text ) . ''; ?>
'; echo '
' . esc_attr( $title ) . '
'; if( $logo ) echo '
' . esc_attr( $title ) . '
'; if( $title || $url ){ $target = $ed_new_tab ? ' target="_blank"' : ''; echo '
'; if( $title ) echo '' . esc_html( $title ) . ''; if( $url && $link ) echo '' . esc_html( $link ) . ''; echo '
'; } echo ''; } } /** * Helper function for listing sponsor */ function benevolent_sponsor_helper( $logo, $url ){ if( $url ) echo ''; if( $logo ) echo '
'; if( $url ) echo '
'; } /** * Helper function for listing stat counter */ function benevolent_stat_helper( $title, $counter ){ if( $counter ){ ?>
' . esc_html( $title ) . ''; ?>
'; echo wp_strip_all_tags( $custom_css ); echo ''; } } add_action( 'wp_head', 'benevolent_custom_css', 100 ); } if ( ! function_exists( 'benevolent_excerpt_more' ) ) : /** * Replaces "[...]" (appended to automatically generated excerpts) with ... * */ function benevolent_excerpt_more( $more ) { return is_admin() ? $more : ' … '; } add_filter( 'excerpt_more', 'benevolent_excerpt_more' ); endif; if ( ! function_exists( 'benevolent_excerpt_length' ) ) : /** * Changes the default 55 character in excerpt */ function benevolent_excerpt_length( $length ) { return is_admin() ? $length : 60; } add_filter( 'excerpt_length', 'benevolent_excerpt_length', 999 ); endif; if( ! function_exists( 'benevolent_footer_credit' ) ) : /** * Footer Credits */ function benevolent_footer_credit(){ $copyright_text = get_theme_mod( 'benevolent_footer_copyright_text' ); $text = '
'; $text .= ''; if( $copyright_text ){ $text .= wp_kses_post( $copyright_text ); }else{ $text .= esc_html__( '© ', 'benevolent' ) . date_i18n( esc_html__( 'Y', 'benevolent' ) ); $text .= ' ' . esc_html( get_bloginfo( 'name' ) ) . ''; } $text .= '.'; if ( function_exists( 'the_privacy_policy_link' ) ) { $text .= get_the_privacy_policy_link(); } $text .= ''; $text .= esc_html__( 'Benevolent | Developed By ', 'benevolent' ); $text .= '' . esc_html__( 'Rara Theme', 'benevolent' ) . '. '; $text .= sprintf( esc_html__( 'Powered by %s', 'benevolent' ), 'WordPress.' ); $text .= '
'; echo apply_filters( 'benevolent_footer_text', $text ); } endif; add_action( 'benevolent_footer', 'benevolent_footer_credit' ); /** * Return sidebar layouts for pages */ function benevolent_sidebar_layout(){ global $post; if( get_post_meta( $post->ID, 'benevolent_sidebar_layout', true ) ){ return get_post_meta( $post->ID, 'benevolent_sidebar_layout', true ); }else{ return 'right-sidebar'; } } /** * Strip specific tags from string * @link http://www.altafweb.com/2011/12/remove-specific-tag-from-php-string.html */ function benevolent_strip_single( $tag, $string ){ $string = preg_replace('/<'.$tag.'[^>]*>/i', '', $string); $string = preg_replace('/<\/'.$tag.'>/i', '', $string); return $string; } if( ! function_exists( 'benevolent_single_post_schema' ) ) : /** * Single Post Schema * * @return string */ function benevolent_single_post_schema() { if ( is_singular( 'post' ) ) { global $post; $custom_logo_id = get_theme_mod( 'custom_logo' ); $site_logo = wp_get_attachment_image_src( $custom_logo_id , 'benevolent-schema' ); $images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); $excerpt = benevolent_escape_text_tags( $post->post_excerpt ); $content = $excerpt === "" ? mb_substr( benevolent_escape_text_tags( $post->post_content ), 0, 110 ) : $excerpt; $schema_type = ! empty( $custom_logo_id ) && has_post_thumbnail( $post->ID ) ? "BlogPosting" : "Blog"; $args = array( "@context" => "https://schema.org", "@type" => $schema_type, "mainEntityOfPage" => array( "@type" => "WebPage", "@id" => esc_url( get_permalink( $post->ID ) ) ), "headline" => esc_html( get_the_title( $post->ID ) ), "datePublished" => esc_html( get_the_time( DATE_ISO8601, $post->ID ) ), "dateModified" => esc_html( get_post_modified_time( DATE_ISO8601, __return_false(), $post->ID ) ), "author" => array( "@type" => "Person", "name" => benevolent_escape_text_tags( get_the_author_meta( 'display_name', $post->post_author ) ) ), "description" => ( class_exists('WPSEO_Meta') ? WPSEO_Meta::get_value( 'metadesc' ) : $content ) ); if ( has_post_thumbnail( $post->ID ) ) : $args['image'] = array( "@type" => "ImageObject", "url" => $images[0], "width" => $images[1], "height" => $images[2] ); endif; if ( ! empty( $custom_logo_id ) ) : $args['publisher'] = array( "@type" => "Organization", "name" => esc_html( get_bloginfo( 'name' ) ), "description" => wp_kses_post( get_bloginfo( 'description' ) ), "logo" => array( "@type" => "ImageObject", "url" => $site_logo[0], "width" => $site_logo[1], "height" => $site_logo[2] ) ); endif; echo '' , PHP_EOL; } } endif; add_action( 'wp_head', 'benevolent_single_post_schema' ); if( ! function_exists( 'benevolent_escape_text_tags' ) ) : /** * Remove new line tags from string * * @param $text * @return string */ function benevolent_escape_text_tags( $text ) { return (string) str_replace( array( "\r", "\n" ), '', strip_tags( $text ) ); } endif; if( ! function_exists( 'benevolent_change_comment_form_default_fields' ) ) : /** * Change Comment form default fields i.e. author, email & url. * https://blog.josemcastaneda.com/2016/08/08/copy-paste-hurting-theme/ */ function benevolent_change_comment_form_default_fields( $fields ){ // get the current commenter if available $commenter = wp_get_current_commenter(); // core functionality $req = get_option( 'require_name_email' ); $aria_req = ( $req ? " aria-required='true'" : '' ); $required = ( $req ? " required" : '' ); $author = ( $req ? __( 'Name*', 'benevolent' ) : __( 'Name', 'benevolent' ) ); $email = ( $req ? __( 'Email*', 'benevolent' ) : __( 'Email', 'benevolent' ) ); // Change just the author field $fields['author'] = '

'; $fields['email'] = '

'; $fields['url'] = '

'; return $fields; } endif; add_filter( 'comment_form_default_fields', 'benevolent_change_comment_form_default_fields' ); if( ! function_exists( 'benevolent_change_comment_form_defaults' ) ) : /** * Change Comment Form defaults * https://blog.josemcastaneda.com/2016/08/08/copy-paste-hurting-theme/ */ function benevolent_change_comment_form_defaults( $defaults ){ $defaults['comment_field'] = '

'; return $defaults; } endif; add_filter( 'comment_form_defaults', 'benevolent_change_comment_form_defaults' ); if( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * Added for backwards compatibility to support pre 5.2.0 WordPress versions. */ function wp_body_open() { /** * Triggered after the opening tag. */ do_action( 'wp_body_open' ); } endif; if( ! function_exists( 'benevolent_get_image_sizes' ) ) : /** * Get information about available image sizes */ function benevolent_get_image_sizes( $size = '' ) { global $_wp_additional_image_sizes; $sizes = array(); $get_intermediate_image_sizes = get_intermediate_image_sizes(); // Create the full array with sizes and crop info foreach( $get_intermediate_image_sizes as $_size ) { if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) { $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' ); $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' ); $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' ); } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { $sizes[ $_size ] = array( 'width' => $_wp_additional_image_sizes[ $_size ]['width'], 'height' => $_wp_additional_image_sizes[ $_size ]['height'], 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'] ); } } // Get only 1 size if found if ( $size ) { if( isset( $sizes[ $size ] ) ) { return $sizes[ $size ]; } else { return false; } } return $sizes; } endif; if ( ! function_exists( 'benevolent_get_fallback_svg' ) ) : /** * Get Fallback SVG */ function benevolent_get_fallback_svg( $post_thumbnail ) { if( ! $post_thumbnail ){ return; } $image_size = benevolent_get_image_sizes( $post_thumbnail ); if( $image_size ){ ?>
urlencode( implode( '|', $font_families ) ), 'display' => urlencode( 'fallback' ), ); $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); } return esc_url( $fonts_url ); } endif; /** * Function to exclude posts in blog index page */ function benevolent_exclude_posts_for_blogpage( $query ) { $show_on_front = get_option( 'show_on_front' ); $ed_slider = get_theme_mod( 'benevolent_ed_slider' ); $slider_category = get_theme_mod( 'benevolent_slider_cat' ); if ( ! is_admin() && $query->is_home() && $query->is_main_query() && $ed_slider && 'posts' == $show_on_front ) { if( $slider_category ){ $query->set( 'category__not_in', $slider_category ); } } } add_action( 'pre_get_posts', 'benevolent_exclude_posts_for_blogpage' );