WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Need to add unique read more link to excerpt

[Resolved] Need to add unique read more link to excerpt

  • 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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mark Root-Wiley

    @mrwweb

    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().

    Plugin Author Mark Root-Wiley

    @mrwweb

    @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!

    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!

    Plugin Author Mark Root-Wiley

    @mrwweb

    Glad to hear it worked!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Need to add unique read more link to excerpt’ is closed to new replies.