ID, 'travel_diaries_sidebar_layout', true ); if( $sidebar_layout == 'no-sidebar' ) $classes[] = 'full-width'; } return $classes; } add_filter( 'body_class', 'travel_diaries_body_classes' ); if( ! function_exists( 'travel_diaries_excerpt' ) ): /** * travel_diaries_excerpt can truncate a string up to a number of characters while preserving whole words and HTML tags * * @param string $text String to truncate. * @param integer $length Length of returned string, including ellipsis. * @param string $ending Ending to be appended to the trimmed string. * @param boolean $exact If false, $text will not be cut mid-word * @param boolean $considerHtml If true, HTML tags would be handled correctly * * @return string Trimmed string. * * @link http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/ */ function travel_diaries_excerpt($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } // splits all html-tags to scanable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = strlen($ending); $open_tags = array(); $truncate = ''; foreach ($lines as $line_matchings) { // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { // do nothing // if tag is a closing tag } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { // delete tag from $open_tags list $pos = array_search($tag_matchings[1], $open_tags); if ($pos !== false) { unset($open_tags[$pos]); } // if tag is an opening tag } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { // add tag to the beginning of $open_tags list array_unshift($open_tags, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); if ($total_length+$content_length> $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { if ($entity[1]+1-$entities_length <= $left) { $left--; $entities_length += strlen($entity[0]); } else { // no more characters left break; } } } $truncate .= substr($line_matchings[2], 0, $left+$entities_length); // maximum lenght is reached, so get off the loop break; } else { $truncate .= $line_matchings[2]; $total_length += $content_length; } // if the maximum length is reached, get off the loop if($total_length>= $length) { break; } } } else { if (strlen($text) <= $length) { return $text; } else { $truncate = substr($text, 0, $length - strlen($ending)); } } // if the words shouldn't be cut in the middle... if (!$exact) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } // add the defined ending to the text $truncate .= $ending; if($considerHtml) { // close all unclosed html-tags foreach ($open_tags as $tag) { $truncate .= ''; } } return $truncate; } endif; // End function_exists /** * Callback for Social Links */ function travel_diaries_social_cb(){ $facebook = get_theme_mod( 'travel_diaries_facebook' ); $twitter = get_theme_mod( 'travel_diaries_twitter' ); $instagram = get_theme_mod( 'travel_diaries_instagram' ); $google_plus = get_theme_mod( 'travel_diaries_google_plus' ); $linkedin = get_theme_mod( 'travel_diaries_linkedin' ); $youtube = get_theme_mod( 'travel_diaries_youtube' ); if( $facebook || $twitter || $instagram || $google_plus || $linkedin || $youtube ){ ?> '; if( $first_label && $first_content ){ $info .= '
  • '. esc_html( $first_label ) .''. esc_html( $first_content ) .'
  • '; } if( $second_label && $second_content ){ $info .= '
  • '. esc_html( $second_label ) .''. esc_html( $second_content ) .'
  • '; } if( $third_label && $third_content ){ $info .= '
  • '. esc_html( $third_label ) .''. esc_html( $third_content ) .'
  • '; } $info .= ''; } echo $info; } add_action( 'travel_diaries_header_info', 'travel_diaries_header_info_cb' ); /** * Hook to move comment text field to the bottom in WP 4.4 * * @link http://www.wpbeginner.com/wp-tutorials/how-to-move-comment-text-field-to-bottom-in-wordpress-4-4/ */ function travel_diaries_move_comment_field_to_bottom( $fields ) { $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; return $fields; } add_filter( 'comment_form_fields', 'travel_diaries_move_comment_field_to_bottom' ); /** * Callback function for Comment List * * * @link https://codex.wordpress.org/Function_Reference/wp_list_comments */ function travel_diaries_theme_comment( $comment, $args, $depth ){ $GLOBALS['comment'] = $comment; extract($args, EXTR_SKIP); if ( 'div' == $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { $tag = 'li'; $add_below = 'div-comment'; } ?> < id="comment-">
    %s', 'travel-diaries' ), get_comment_author_link() ); ?>
    comment_approved == '0' ) : ?>
    $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    array( 'class' => 'banner', 'id' => 'banner' ), 'featured-section' => array( 'class' => 'featured-on', 'id' => 'featuredon' ), 'recent-section' => array( 'class' => 'recent-posts', 'id' => 'recentpost' ), 'article-section' => array( 'class' => 'popular-posts', 'id' => 'populararticle' ), 'clients-section' => array( 'class' => 'clients', 'id' => 'client' ), 'guide-section' => array( 'class' => 'guide', 'id' => 'guide' ) ); $enabled_section = array(); foreach ( $sections as $section ) { if ( esc_attr( get_theme_mod( 'travel_diaries_ed_' . $section['id'] . '_section' ) ) == 1 ){ $enabled_section[] = array( 'id' => $section['id'], 'class' => $section['class'] ); } } return $enabled_section; } /** * Custom CSS */ function travel_diaries_custom_css(){ $custom_css = get_theme_mod( 'travel_diaries_custom_css' ); if( !empty( $custom_css ) ){ echo ''; } } add_action( 'wp_head', 'travel_diaries_custom_css', 100 ); if ( ! function_exists( 'travel_diaries_excerpt_more' ) && ! is_admin() ) : /** * Replaces "[...]" (appended to automatically generated excerpts) with ... * */ function travel_diaries_excerpt_more() { return ' … '; } add_filter( 'excerpt_more', 'travel_diaries_excerpt_more' ); endif; if ( ! function_exists( 'travel_diaries_excerpt_length' ) ) : /** * Changes the default 55 character in excerpt */ function travel_diaries_excerpt_length( $length ) { return 35; } add_filter( 'excerpt_length', 'travel_diaries_excerpt_length', 999 ); endif; /** * Footer Credits */ function travel_diaries_footer_credit(){ $text = ''; $text .= esc_html__( 'Copyright © ', 'travel-diaries' ) . date('Y'); $text .= ' ' . esc_html( get_bloginfo( 'name' ) ) . '. '; $text .= ''; $text .= esc_html__( 'Theme Travel Diaries by ', 'travel-diaries' ); $text .= '. '; $text .= sprintf( esc_html__( 'Powered by %s', 'travel-diaries' ), 'WordPress.' ); $text .= ''; echo apply_filters( 'travel_diaries_footer_text', $text ); } add_action( 'travel_diaries_footer', 'travel_diaries_footer_credit' ); /** * Function for logo listing */ function travel_diaries_logo_listing( $logo, $link = false, $client = false ){ $return = ''; if( $logo ){ $return = ( $client == true ) ? '
    ' : '
  • '; if( $link ) $return .= ''; $return .= ''; if( $link ) $return .= ''; $return .= ( $client == true ) ? '
  • ' : ''; echo $return; } }