Community Forums › Forums › Archived Forums › Design Tips and Tricks › Using Excerpts Instead of Content Limit Teasers – Magazine Pro
Tagged: content limi, excerpts, Magazine Pro, more link, read more
- This topic has 8 replies, 2 voices, and was last updated 10 years, 1 month ago by
Ren Ventura.
-
AuthorPosts
-
January 12, 2015 at 5:48 pm #137258
eluviis
MemberI've decided to use custom excerpts instead of automatic content limit teasers in my new update to Magazine Pro. However, I noticed the fancy "Read More" button doesn't work when you select excerpts for your homepage widgets or archive pages.
I looked in the WP codex and found this bit of code to add to functions.php:
function new_excerpt_more( $more ) { return ' <a class="more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>'; } add_filter( 'excerpt_more', 'new_excerpt_more' );
Note, the original code uses the class "read-more" but I changed that bit to "more-link" as examining the site with Firebug told me that's what magazine-pro uses for the Read More buttons.
That said, it still doesn't work.
Any ideas?
January 12, 2015 at 7:23 pm #137266Ren Ventura
MemberTake a look at the post I just wrote:
http://www.engagewp.com/customize-wordpress-read-more-link/
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 12, 2015 at 8:03 pm #137269eluviis
MemberAh! I just read that and I thought it would be as simple as adding the <!--more--> tag to my excerpts to make the snippet I got from the codex to work... But nope. That didn't do it.
I'm going to have to take more time and try one of your snippets there and see if I can make it work.
The reality is I DON'T NEED the read more button, because I believe the image and the title are enough to have the reader click. The problem is that the posts that DON'T have custom excerpts are still having excerpts automatically pulled from the text and those posts are rendering the READ MORE button where the ones with custom manual excerpts are not. So I end up with some posts with and some posts without. Which looks weird.
January 12, 2015 at 8:49 pm #137279Ren Ventura
MemberThe problem is that the posts that DON’T have custom excerpts are still having excerpts automatically pulled from the text and those posts are rendering the READ MORE button where the ones with custom manual excerpts are not.
That's because the link needs to be appended to a custom excerpt. I just updated the code to include a snippet that removes WordPress-generated excerpts, meaning there won't be an excerpt if you don't set one. You can combine the last two snippets to get what you're looking for:
/** * Removes excerpts that are generated by WordPress rather than set by user * and adds the Read More link to the excerpt */ add_filter( 'get_the_excerpt', 'rv_remove_non_custom_excerpts' ); function rv_remove_non_custom_excerpts( $output ) { global $post; if ( $post->post_excerpt == '' ) { $output = ''; } else { $output .= rv_filter_read_more_link(); } return $output; }
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 15, 2015 at 3:16 pm #137596eluviis
MemberHi @Ren Ventura, thanks for that. However, I might have caused a misunderstanding.
If I'm going to be able to add the read more link to custom excerpts, I don't want to stop WP from rendering automatic excerpts from posts that don't have a custom except. I just want to add the read more link to custom excerpts so they match all the posts.The reason for this is I have many posts. It'll take me a while to go back and add custom excerpts to all of them. While I get that done, I don't want those posts to render blank excerpts in the meantime. But I do want both custom excerpts and automatic excerpts to have the read more link.
Hope that makes sense. :/
Big thanks again,
DannyJanuary 15, 2015 at 8:59 pm #137613Ren Ventura
MemberNot a problem. I think I just misunderstood what you were looking to do (I thought your preference was to remove the excerpt generated by WordPress).
In any case, the code is still included in the post I linked to above. Try this exact snippet:
add_filter( 'excerpt_more', 'rv_filter_read_more_link' ); add_filter( 'get_the_excerpt', 'rv_do_excerpt_read_more_link' ); function rv_do_excerpt_read_more_link( $output ) { global $post; if ( $post->post_excerpt != '' ) { $output .= rv_filter_read_more_link(); } return $output; } //* Function that returns the actual link function rv_filter_read_more_link() { return sprintf( '%3$s', get_permalink(), 'readmore', __( ' [Keep on reading!]' ) ); }
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 15, 2015 at 9:07 pm #137615Ren Ventura
MemberI tried fixing the HTML formatting of the last reply but it wouldn't let me. Here's a link instead:
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 19, 2015 at 1:39 pm #137966eluviis
Member@Ren Ventura - What can I tell you? That worked! Thanks.
I changed the class of "%2$s" you had there for "more-link" and it picked up Magazine Pro's CSS style for that on the homepage, which is nice. I'm not sure what "%2$s" does or even means, but the style works with the change.
I also changed the link text from [Keep on reading!] to [ Show me more... ]
You can see it in action here: http://rallyways.com
Thanks again,
DannyJanuary 19, 2015 at 4:17 pm #137987Ren Ventura
MemberAwesome! Glad to see you got it working.
The "%2$s" is a part of the printf() function, which is basically an easier way of formatting a string when it's generated at least partially by functions and variables. Replacing it with your own text is perfectly fine.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.