How To Modify “the_excerpt” in WordPress

These are a few pretty simple tricks that can actually be found if you go to WordPress and look in the reference for the_excerpt() function but I figured I would show you how I have customized it for my own installation.

The first two, in my opinion, work hand in hand because they actually modify the length and the “Read More” options of the_excerpt. These are typically the more two requested features that people like to change. For these just take the code below and drop it in your “functions.php” file located in your wp-content/themes/your-theme/ folder where “your-theme” is whatever theme you would like to have this work with.

Heres the code:

//Modify the length of the_excerpt
function new_excerpt_length($length) {
	return 150;
}
add_filter('excerpt_length', 'new_excerpt_length');
 
//Modify the "Read More" link of the_excerpt
function new_excerpt_more($more) {
	$new = str_replace("Continue reading ", "Read More", $more);
	$new = str_replace('<span class="meta-nav">→</span>', "", $new);
	return $new;
}
add_filter('excerpt_more', 'new_excerpt_more');

What this code is doing is created two new functions that will return a value to the_excerpt function when the filters are applied.

The first function if you haven’t guessed changes the length of the_excerpt so that it can show more than its default of 55 words.

The second is actually setup to take the default link that will send the user to the page with a “Read More” style link and allow the developer to change it. With the case of WordPress 3 they changed the end of the excerpt to say “Continue reading ” which we want to modify. As this changes you will just have to inspect the html of the page to find the current use and change the function replacing variables.

The other option that is available to change the_excerpt in a bigger way is to just create your own the_excerpt type of function within your “functions.php” folder. With the abilities of filters and other things its not typically as necessary.

New Year Resolution for Web Developers

With another year gone comes another chance to take advantage of what we missed. Heres a quick list of some New Years resolutions that I will be partaking in and some of you may be interested in also…

#1 Get Smarter

This can be as easy as getting a new html/css book or learning about new standards on the web. If your anything like me though you want to try and take it up a notch and do something like learn a new language. On my list to learn this year is Ruby on Rails. I have wanted to learn this language for quite a while now but as with life it gets pushed aside when its not important. However you do it just learn something new.

#2 Get Outside

Go outside and be active. Join a local intramural sports team, go to the gym, go for a run, or hell, just leave the cave where your computer resides and go for a walk. Getting exercise and change from the normal day to day activities can make a huge difference. Since I work from home it can be really hard to get up and leave my computer which is why its important to have some activities planned that make me get out and stay fit.

#3 Get Organized

Everyone has issues with keeping things organized, whether its work meetings, project due dates, appointments, or just the casual hang out with a friend. Finding a way to stay on top of it can be a hassle but it definitely will make life much easier and less stressful. For work organization we at Avelient use a variety of tools to keep on task with projects but our biggest asset is definitely the37signals suite of products. If you haven’t heard of them, definitely check them out. It will make your life easier.

#4 Get Creative

Find a side project to get your creative juices flowing. Monotony will kill the joy that you have for the work that you do. You gotta switch it up and keep your mind working so that you can create better and unique products. Why not tie a new project with the idea from the “Get Smarter” section and create something different while learning a new language. Or another option could be to create something using your current toolset in a different way. As an example if you know JQuery, use JQuery Mobile to setup a new mobile site for your current website and test some of its new features. Just keep that passion that you have for whatever you do.