Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #515620

    Hi,

    I found a strange behavior about the masonry & magazine shortcades.
    If there is no breakpoint, but some tags in our pages, both the masonry blog & magazine shorcodes will show the whole post contents.

    So I traced the shortcodes and found that function avia_backend_truncate() is the cause of the problem.
    This function didn’t treat the situation if there is no breakpoint and exists some tags

    I’ve these codes in functions.php of my enfold-child

    // modify masonry excerpt length
    add_filter( 'avf_masonry_excerpt_length', 'avf_masonry_excerpt_length_mod');
    function avf_masonry_excerpt_length_mod() {
    	$excerpt = 30;
    	return $excerpt;
    }
    
    // modify magazine excerpt length
    add_filter( 'avf_magazine_excerpt_length', 'avf_magazine_excerpt_length_mod');
    function avf_magazine_excerpt_length_mod() {
    	$excerpt = 40;
    	return $excerpt;
    }
    
    // modify magazine delimiter <!--magazine-->
    add_filter( 'avf_magazine_excerpt_delimiter', 'avf_magazine_excerpt_delimiter_mod');
    function avf_magazine_excerpt_delimiter_mod() {
    	$break = "<!--magazine-->";
    	return $break;
    }
    
    // modify masonry delimiter <!--masonry-->
    add_filter( 'avf_masonry_excerpt_delimiter', 'avf_masonry_excerpt_delimiter_mod');
    function avf_masonry_excerpt_delimiter_mod() {
    	$break = "<!--masonry-->";
    	return $break;
    }
    
    // excerpt truncate function modified for Chinese
    function avia_backend_truncate($string, $limit, $break=".", $pad="...", $stripClean = false, $excludetags = '<strong><em><span>', $safe_truncate = false)
    {
    
    	if(strlen($string) <= $limit) return $string;
    
    	// if exists $breakpoint
    	if(false !== ($breakpoint = strpos($string, $break)))
    	{
    		if($breakpoint < strlen($string) - 1)
    		{
                        	$string = substr($string, 0, $breakpoint) . $pad;
                 	}
    	} 
    	// if no $breakpoint
    	else
    	{
                    $string = wp_trim_words($string, $limit) ;
    	}
    
    	// strip unwanted HTML tags
    	if($stripClean)
    	{
    		$string = strip_shortcodes(strip_tags($string, $excludetags));
    	}
    
    	return $string;
    }
    

    I moved the [//strip unwanted HTML tags] part to the last, because it will strip the breakpoint like <!–magazine–>, <!–masonry–> and <!–more–>.
    And I use wp_trim_words() function to avoid some problems in Chinese words.

    There is a post about the wordpress excerpt problem for Chinese,
    http://wptutorial.narrativecard.com/wordpress-excerpt-problem-chinese/

    #516210

    Hey faithbackpacker!

    Thank you for using Enfold and the included fix. What do you mean by “breakpoints”? Or try to add the summary in the Excerpt box.

    Cheers!
    Ismael

    #517092

    Hi Ismael,

    If there is no mistake, I think “breakpoint” is the delimiter of excerpt.

    Normal excerpt delimiter is
    <!--more-->
    But it’s too long for magazine and masonry, so I use
    <!--magazine--> & <!--masonry-->
    instead.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Masonry & Magazine shortcodes bugs’ is closed to new replies.