Use WP Custom Fields to change Read More button text?

  • gaiiden


    I love your theme, works great for my site ( Was just writing up a post and wanted it to be broken up into a section of pertinent information to display on the main page followed by a more detailed section to come after a Read More tag. But I also want to tell people what’s in the section. I feel awkward putting a sentence at the end of the first section saying “Read on for more details about the flight data analysis” because in the actual article (when not viewed from the front page) the Read More link isn’t there. So that made me think if there was a way to use the WP post Custom Fields to define a caption for the Read More button, so instead of just saying “Read the rest of this entry »” by default I could tell it to say “Read more on the Flight Data Analysis »” instead. Or anything else I want to specify.

    I’m a programmer but not yet well-versed in PHP and coding stuff for WP themes. Just let me know if you think something like this would be possible to setup with your theme, and I’ll figure out how to do it. Thanks!


    Syahir Hakim


    if you just would like to change the wording on all the posts, you can use the code as detailed here:

    If you would like a more granular control, e.g. different wording for different posts, as you suggested you would need to create a custom field for that. Then, you’ll need to modify the suggested code linked to above to get the custom field value and use that instead.



    hrm… I didn’t understand how that code you linked to related to the “Read the rest of this entry” button, so I decided to brute-force it and just did a search to find out where the button text was being applied and modified the loop.php file to be

    $moretext = get_post_meta(get_the_ID(), 'more text', true);
    if (strlen($moretext)) {
    the_content( '<span class="block-button">' . __( $moretext . ' &raquo;', 'graphene' ) . '</span>' );
    } else {
    the_content( '<span class="block-button">' . __( 'Read the rest of this entry &raquo;', 'graphene' ) . '</span>' );
    } ?>

    And that works great, but yea I’m modifying your base code so that’s not really the most elegant of solutions I know. But hopefully you have a better idea of what I’m asking.

    Or perhaps you do understand and I just need a better idea of how to modify that code snippet you linked me to, because I really can’t figure it out.


    Syahir Hakim


    You can do something like this:

    function graphene_filter_gettext( $translated, $original, $domain ) {
    	if ( is_singular() ){
    		$moretext = get_post_meta( get_the_ID(), 'more text', true );
    		if ( $moretext ) {
    			$strings = array(
    				'Read the rest of this entry »' => $moretext,
    	if ( ! empty( $strings[$original] ) ) {
    		$translations = &get_translations_for_domain( $domain );
    		$translated = $translations->translate( $strings[$original] );
    	return $translated;
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );



    thanks, that helps. Much appreciated



    Hey, I’m joining the question.
    Is there a possibility to do this without coding? I do not understand coding at all…
    Another question.
    Can I change the posts automatically displayed on the homepage so I can choose which posts to show?

Viewing 6 posts - 1 through 6 (of 6 total)

  • You must be logged in to reply to this topic.
Graphene Themes Forum