Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Last active August 13, 2017 07:13
Show Gist options
  • Save mehul0810/b99b04a5d66013f43dd5653678da80dc to your computer and use it in GitHub Desktop.
Save mehul0810/b99b04a5d66013f43dd5653678da80dc to your computer and use it in GitHub Desktop.
<?php
/**
* This function will help to create different excerpt length for different post types.
*
*/
function mg_variable_excerpt_length( $length ) {
// Declare $post global variable to detect current post type.
global $post;
// Check for the type of post type and based on which assign the excerpt length for each post type.
if ( 'post' === $post->post_type ) {
return 32;
} else if ( 'page' === $post->post_type ) {
return 65;
} else if ( 'products' === $post->post_type ) {
return 75;
} else {
return 80;
}
}
add_filter( 'excerpt_length', 'mg_variable_excerpt_length');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment