in Wordpress Stuffs

Congratulations, You’ve Won a WordPress Snippet!

After constantly forgetting about these quick tweaks to excerpts in WordPress, I figured I would put them somewhere memorable. Like my blog and GitHub (making my first gist as well). So, enjoy two quick WordPress snippets:

[gist id=3352179]

What you are seeing here are two minor ways to tweak WordPress’ excerpt to be a bit more robust and configurable. The second bit of code is rather straight forward: you can easily change the number of words that are displayed in an excerpt. This can be very useful when having a mini list of posts in a sidebar and you only have a fixed amount of space.

The first bit of code is where you can get a bit fancier. This is changing the […] you always see at the end of an excerpt. The ellipsis can be annoying since depending on the theme you are working with, you might or might not have a link to the post at the end of the excerpt. What the function does is completely replace the […] at the end of the excerpt with whatever you have within the ” after the return. What you see here is that I have it set to add an ellipsis then “Read More…” wrapped with a permalink to the post. This is nice from a usability standpoint because it gives the reader/user an obvious way to continue reading the post.

But you can get even fancier than what I have in the code. One way to fancy it up is to add a particular function that links into a plugin that you only want to use on pages that show excerpts. For instance, you could have the end of the excerpt enqueue a sharing plugin that you made that had originally only shown up on single posts. Another thing you can do is also add the post meta information at the end rather than the beginning of the excerpt.

Really, the possibilities are endless but I know I always forget such simple things when trying to tackle larger problems. Hopefully more snippets are to come. Some point soon may have me showing you how to work Sublime Text 2 into a super editor.

Write a Comment