WordPress.org

Ready to get started?Download WordPress

Forums

Feature A Page Widget
[resolved] Need to add unique read more link to excerpt (5 posts)

  1. laughhearty
    Member
    Posted 1 year ago #

    Hi!
    Is there a way to add a unique read more link. I've used this code to get "Read More" after the excerpt:

    function test_func( $excerpt, $featured_page_id ) {
        return $excerpt . '</p><p class="read-more-wrapper"><a class="read-more-link" href="' . get_permalink( $featured_page_id ) . '">Read More</a>';
    }
    add_filter( 'fpw_excerpt', 'test_func', 10, 2 );

    My client wants the excerpt from the services page to say: "Services".
    Is it possible to add a conditional to the code to target a single pages excerpt no matter which page it appears on?

    Thanks!

    http://wordpress.org/extend/plugins/feature-a-page-widget/

  2. mrwweb
    Member
    Plugin Author

    Posted 1 year ago #

    Should be hard. As you can see, the filter passes two argument, $excerpt and $featured_page_id. That second lets you do all sorts of fun stuff.

    If this is a one-off change and you need to test for the page's ID, you can do that by replacing XX with the page's ID in the snippet below:

    function fapw_read_more( $excerpt, $featured_page_id ) {
        if( $featured_page_id == XX ) {
            $fapw_read_more_text = 'Services';
        } else {
            $fapw_read_more_text = 'Read More';
        }
        return $excerpt . '</p><p class="read-more-wrapper"><a class="read-more-link" href="' . get_permalink( $featured_page_id ) . '">' . $fapw_read_more_text . '</a>';
    }
    add_filter( 'fpw_excerpt', 'fapw_read_more', 10, 2 );

    Or, you may really just want to repeat the title of the page:

    function fapw_read_more( $excerpt, $featured_page_id ) {
        $fapw_read_more_text = 'Continue Reading "' . get_the_title( $featured_page_id ) .'"…';
        return $excerpt . '</p><p class="read-more-wrapper"><a class="read-more-link" href="' . get_permalink( $featured_page_id ) . '">' . $fapw_read_more_text . '</a>';
    }
    add_filter( 'fpw_excerpt', 'fapw_read_more', 10, 2 );

    That would change "Read More..." to "Continue Reading "Services"..."

    Those are just two options. With the ID, you can do just about anything you want. For instance, you could make a custom field to store read more text for the page and then grab it with get_post_meta().

  3. mrwweb
    Member
    Plugin Author

    Posted 1 year ago #

    @laughhearty

    Please let me know if this worked for you and I can mark it "resolved" or whether you're still having trouble. I'm happy to help if you're still stuck!

  4. laughhearty
    Member
    Posted 1 year ago #

    Yes,
    it's taken this long to back to this thread. I've been so BUSY with other projects.
    Just wanted to officially state:

    This works like a charm!

    Thanks again. I love this plugin and have waiting for something like this to come along in a long time!

  5. mrwweb
    Member
    Plugin Author

    Posted 1 year ago #

    Glad to hear it worked!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic