Last active
August 13, 2017 07:13
-
-
Save mehul0810/b99b04a5d66013f43dd5653678da80dc to your computer and use it in GitHub Desktop.
Different Excerpt Length for Different Post Types https://www.mehulgohil.in/managing-different-excerpt-length-different-post-types/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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