WordPress.org

Ready to get started?Download WordPress

Forums

How to add custom text between content and more link in the_content (7 posts)

  1. mtpultz
    Member
    Posted 2 years ago #

    I tried to do this but " my custom text" appears after the more link

    function wp_new_content($content) {
    return $content." my custom text";
    }
    add_filter('the_content', 'wp_new_content');

    I thought I could do it the same as the excerpt function below using get_the_content but instead replacing $text for $content and not checking for empty string but that doesn't work. So was trying to using the_content instead.

    [code moderated - please follow the forum guidelines]

  2. Mat Lipe
    Member
    Posted 2 years ago #

    If you would like your text to display after the content you will want to use the add_action functions instead of add_filter. e.g.

    function wp_new_content() {
    echo "my custom text";
    }
    add_action('the_content', 'wp_new_content');

    Give that a try.

  3. Mat Lipe
    Member
    Posted 2 years ago #

    I just realized the example I gave you will replace all the text. Try this instead.

    function wp_new_content($content) {
    echo $content."my custom text";
    }
    add_action('the_content', 'wp_new_content');

  4. mtpultz
    Member
    Posted 2 years ago #

    Thanks for the reply Mat, I tried the above but it still comes out after the more link I copied and pasted the page text below.

    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent viverra lorem ut leo bibendum mattis egestas quam mollis. Donec at lacus sem. Sed fermentum cursus tellus sit amet bibendum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus ultrices ipsum sed quam viverra sit amet ornare metus ornare. Integer eu erat sit amet justo tristique ultrices. Morbi tristique, nisl ut dignissim congue, est velit blandit tellus, at rhoncus felis velit iaculis nisi.

    Continue reading

    my custom text"

  5. Mat Lipe
    Member
    Posted 2 years ago #

    I had to put my thinking cap on to remember how to do this, but I think I figured it out... See Below

  6. Mat Lipe
    Member
    Posted 2 years ago #

    `add_filter( 'excerpt_more', 'child_read_more_link' );
    add_filter( 'get_the_content_more_link', 'child_read_more_link' );
    add_filter( 'the_content_more_link', 'child_read_more_link' );
    /**
    * Custom Read More link.
    *
    */
    function child_read_more_link() {

    return 'my custom Text <a href="' . get_permalink() . '" rel="nofollow">Continue Reading …</a>';

    }

  7. mtpultz
    Member
    Posted 2 years ago #

    Hi Mat, thanks for the help that works great!!! I really appreciate the help :)

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic