• Resolved malone76

    (@malone76)


    Hi Ben,

    What would be the proper way to change the “Read The Post” to say something else or be a button image?

    I’ve already got a blank child theme with some minor mods from the other threads here.

    Initially I tried creating a blank functions.php in the child theme with the following code:

    <?php // filter the link on excerpts
    function ct_tracks_excerpt_read_more_link($output) {
    	global $post;
    	return $output . "<p><a class='more-link' href='". get_permalink() ."'>" . __('[Read More]', 'tracks') . "<span class='screen-reader-text'>" . get_the_title() . "</span></a></p>";
    }
    ?>

    I’m getting a re-declare error.

    I can get it to work properly by editing the functions.php of the parent theme to my liking but I don’t want to end up losing changes when upgrading the theme.

    Edit:
    Link to site – https://mikeymalone.com/

    Currently I edited the Tracks parent theme functions.php to achieve it, just know that it’s going to get lost down the road at theme upgrade.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter malone76

    (@malone76)

    Edit:
    After reading here I can see why it’s giving the redeclare error as the childtheme is declaring the function prior to the parent, but not sure how to get around it.

    Theme Author Ben Sibley

    (@bensibley)

    Sure, there are just a few small edits that need to be made.

    The following code will work:

    function my_tracks_excerpt_read_more_link($output) {
    	global $post;
    	return $output . "<p><a class='more-link' href='". get_permalink() ."'>" . __('Read the Post', 'tracks') . "<span class='screen-reader-text'>" . get_the_title() . "</span></a></p>";
    }
    add_filter('the_excerpt', 'my_tracks_excerpt_read_more_link', 999);

    In the above code, the function has been given a unique name. It is then “hooked” to the “the_excerpt” filter. The “999” parameter is added to ensure it runs after the parent theme’s version of this function. This way, whatever your change the “read more” text to in your child theme, it will override the default version in the parent theme.

    Thread Starter malone76

    (@malone76)

    Excellent, this worked like a charm. I knew I was missing something simple.

    Theme Author Ben Sibley

    (@bensibley)

    Great, glad it’s working for you ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing "Read The Post"’ is closed to new replies.