Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Last active August 13, 2017 07:20
Show Gist options
  • Save mehul0810/2df61e54ec6a2c1c4fb228b94d4c0507 to your computer and use it in GitHub Desktop.
Save mehul0810/2df61e54ec6a2c1c4fb228b94d4c0507 to your computer and use it in GitHub Desktop.
Different Read More Text for Different Post Types
<?php
/**
* This function will help to create different text for read more of different post types.
*
*/
function mg_variable_excerpt_read_more( $more ) {
// Declare $post global variable to detect current post type.
global $post;
// Check for the post type based on which assign the read more text for each post type.
if ( 'post' === $post->post_type ) {
return __( 'Continue Reading', 'textdomain' );
} else if ( 'page' === $post->post_type ) {
return __( 'Take a look', 'textdomain' );
} else if ( 'products' === $post->post_type ) {
return __( 'Look at this product.', 'textdomain' );
} else {
return __( 'Read More', 'textdomain' );
}
}
add_filter( 'excerpt_more', 'mg_variable_excerpt_read_more' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment