How to stop unwanted splits in excerpts when using shortcodes for sliders or players
Am using this code in functions.php: Issue with enabling formatting in excerpts in Wordpress
to allow shortcodes, javascript and formatting in the excerpt - works great, thanks.
However, I am also using a slider (slideshow satellite), which breaks if I set my excerpt length too low (the slideshow size is obviously related to its content). Does anyone know a way to keep the excerpt length low but when a post has a player/slider called by shortcode, make sure it finishes the embedded code, no matter how long it is?
Thanks
functions.php:
function better_trim_excerpt($text)
{
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
//$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]', ']]gt;', $text);
// Enable formatting in excerpts - Add HTML tags that you want to be parsed in excerpts, default is 55
//$text = strip_tags($text, 'strongbemiacodekbdimg');
// Set custom excerpt length - number of words to be shown in excerpts
$excerpt_length = apply_filters('excerpt_length', 900);
// Modify excerpt more string at the end from [...] to ...
$excerpt_more = apply_filters('excerpt_more', ' ' . '...');
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
// IMPORTANT! Prevents tags cutoff by excerpt (i.e. unclosed tags) from breaking formatting
$text = force_balance_tags( $text );
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
// Remove the native excerpt function, and replace it with our improved function
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'better_trim_excerpt');
Slideshow satellite default.php:
?php
global $satellite_init_ok;
if (!empty($slides)) :
$style = $this-get_option('styles');
$images = $this-get_option('Images');
$imagesbox = $images['imagesbox'];
$pagelink = $images['pagelink'];
$textloc = $this-get_option('textlocation');
$responsive = $this-get_option('responsive');
$respExtra = (isset($respExtra)) ? $respExtra : 0;
$align = $this-get_option('align');
if (!$frompost) {
$this-Gallery-loadData($slides[0]-section);
$sidetext = $this - Gallery - capLocation($this-Gallery-data-capposition,$slides[0]-section);
}
?
?php if ($frompost) : ?
!-- =======================================
THE ORBIT SLIDER CONTENT
======================================= --
div class="orbit-default
?php echo($this-get_option('thumbnails_temp') == 'Y') ? ' default-thumbs' : ''; ?
?php echo($align) ? ' satl-align-' . $align : ''; ?
?php echo($responsive) ? ' resp' : ''; ?
"
div id="featured?php echo $satellite_init_ok; ?"
?php foreach ($slides as $slider) :
$thumbnail_link = wp_get_attachment_image_src($slider-ID, 'thumbnail', false);
$attachment_link = get_attachment_link($slider-ID);
$class= ($images['position'] == "S") ? "stretchCenter" : "absoluteCenter";
echo "div class='sorbit-wide ".$class."'
data-caption='#post-{$slider-ID}'
data-thumb='{$thumbnail_link[0]}'";
$this-render('display-image',
array('frompost' = true,
'slider' = $slider), true, 'orbit');?
/div
?php $this - render('display-caption',
array( 'frompost' = true,
'slider' = $slider,
'fontsize' = null,
'style' = $style,
'i' = null
), true, 'orbit');?
?php endforeach; ?
/div !-- end featured --
/div
?php $this - render('jsinit', array('gallery'=false,'frompost' = true,'respExtra' = 0), true, 'orbit');?
!-- CUSTOM GALLERY --
?php else : ?
div class="orbit-default
?php echo($this-get_option('thumbnails_temp') == 'Y') ? ' default-thumbs' : ''; ?
?php echo($sidetext) ? ' text-' . $sidetext : ''; ?
?php echo($align) ? ' satl-align-' . $align : ''; ?
?php echo($responsive) ? ' resp' : ''; ?
"
div id="featured?php echo $satellite_init_ok; ?"
?php $i = 0; ?
?php foreach ($slides as $slider) : ?
?php
$class= ($images['position'] == "S") ? "stretchCenter" : "absoluteCenter";
echo "div id='satl-custom-{$this-Gallery-data-id}{$slider-id}' class='sorbit-wide ".$class."'
data-caption='#custom{$satellite_init_ok}-$i'
data-thumb='{$this-Html-image_url($this-Html-thumbname($slider-image))}'";
$this-render('display-image',
array('frompost' =false,
'slider' = $slider), true, 'orbit');?
/div
?php
if ($sidetext != ( "Disabled" )) :
if ($slider-textlocation != "N") :
?
?php $this - render('display-caption',
array( 'frompost' = false,
'slider' = $slider,
'fontsize' = $this-Gallery-data-font,
'style' = $style,
'i' = $i
), true, 'orbit');?
?php else : ?
span class="sattext-none" id='custom?php echo ($satellite_init_ok . '-' . $i); ?'
/span
?php
endif;
endif;
$i = $i + 1;
endforeach;
?
/div
/div
?php $this - render('jsinit', array('gallery'=$slides[0]-section,'frompost' = false, 'respExtra' = $respExtra), true, 'orbit');?
?php
endif;
/* * ****** PRO ONLY ************* */
if (SATL_PRO $this-get_option('keyboard') == 'Y') {
require SATL_PLUGIN_DIR . '/pro/keyboard.html';
}
endif;
?