By default Genesis includes a read more link that looks like [Read More...]
, which is okay but sometimes we want to change the wording of the link text.
Most of the snippets that I’ve seen for changing the read more link text (except Mika’s) cause you to sacrifice a really great accessibility feature found in the default Genesis read more link: screen reader text. Screen reader text improves the accessibility of your theme and is simple to add with the function genesis_a11y_more_link()
that was included in Genesis version 2.2.
If you want to include screen reader text with your modified read more links, use this:
This file contains 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 | |
add_filter( 'get_the_content_more_link', 'prefix_change_more_link_text' ); | |
/** | |
* Replaces the default Genesis [Read More...] with Read More. | |
* | |
* @param string $more_link The content more link. | |
* | |
* @return string | |
*/ | |
function prefix_change_more_link_text( $more_link ) { | |
$new_more_link_text = __( 'Read More', 'child-theme-text-domain' ); | |
return sprintf( '… <a href="%s" class="more-link">%s</a>', | |
get_the_permalink(), | |
genesis_a11y_more_link( $new_more_link_text ) | |
); | |
} |
Two things to be conscious of, though:
- Your Genesis child theme must declare support for the
'genesis-accessibility'
feature. If it doesn’t already, then you can add the necessary theme support with this code. - Your Genesis child theme needs to have some CSS to hide the screen reader text. You’ll want to add something like this in your stylesheet if it’s not there already.
Leave a Reply