Genesis Read More Link - Change the HTML and Text
Here are the instructions for you: | |
1. Watch the video that walks you through this | |
2. Create a new folder in your theme's `lib` folder called `structure`. | |
3. Inside of `structure`, add the `post.php` file below. Just copy and paste it into that folder. | |
4. In your `functions.php file`, paste this line of code: `include( CHILD_DIR . '/lib/structure/post.php' );`, which loads up your new `post.php` file. | |
5. Now in your `style.css` file, you need to find the following: | |
a. find here the `button` style is and then add `.more-link,` above it. Watch the video to see where to do this. | |
b. find the `button:hover,` and then add this above it: `.more-link:hover,`. | |
Customize the text `Continue reading` to be whatever you want it to be on line 25 in the `post.php` file. | |
Happy Coding! |
<?php | |
/** | |
* Post structure handling | |
* | |
* @package Altitude | |
* @since 1.0.0 | |
* @author hellofromTonya | |
* @link https://knowthecode.io | |
* @license GNU General Public License 2.0+ | |
*/ | |
add_filter( 'the_content_more_link', 'altitude_change_the_read_more_link' ); | |
add_filter( 'get_the_content_more_link', 'altitude_change_the_read_more_link' ); | |
/** | |
* Change the Read More Link HTML Markup and content. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $html | |
* | |
* @return string | |
*/ | |
function altitude_change_the_read_more_link( $html ) { | |
$html = altitude_change_read_more_text( $html, __( 'Continue reading', 'altitude' ) ); | |
if ( doing_filter( 'get_the_content_more_link' ) ) { | |
$html = altitude_strip_off_read_more_opening_dots( $html ); | |
return '</p><p>' . $html; | |
} | |
return sprintf( '<p>%s</p>', $html ); | |
} | |
/** | |
* Strips off the read more link's opening dot pattern. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $html | |
* @param string $dots Dots pattern to strip off | |
* | |
* @return string | |
*/ | |
function altitude_strip_off_read_more_opening_dots( $html, $dots = '… ' ) { | |
return substr( $html, strlen( $dots ) ); | |
} | |
/** | |
* Replace the read more text from the Genesis default text of '[Read more...]' to | |
* the new specified replacement text. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $html Read more link HTML | |
* @param string $replacement_text Replacement text | |
* | |
* @return string | |
*/ | |
function altitude_change_read_more_text( $html, $replacement_text ) { | |
$text_to_replace = __( '[Read more...]', 'altitude' ); | |
return str_replace( $text_to_replace, $replacement_text, $html ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment