Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* @author AppPresser
*
*
* If you would like to shorten the title
* when using the AppSwiper plugin for the
* product post_type.
*
* Place this code your child theme's functions.php
*/
add_filter('the_title', 'my_woo_swiper_title');
function my_woo_swiper_title( $title ) {
global $post;
$max_words = 5;
if( isset( $post, $post->post_type ) && $post->post_type == 'product' ) {
$short_title = '';
$words = explode( ' ', $title);
for($i=0; $i<=$max_words;$i++) {
$short_title .= $words[$i] . ' ';
}
$title = trim($short_title);
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.