Last active
August 13, 2017 07:20
-
-
Save mehul0810/2df61e54ec6a2c1c4fb228b94d4c0507 to your computer and use it in GitHub Desktop.
Different Read More Text for 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 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