WordPress Hidden Gem: get_extended()

I’ve been a WordPress fan for quite a long time now, and one of my favorite parts about that particular piece of software is that I still learn new things about it on a fairly consistent basis. When you build extremely custom websites for clients, there are often out of the ordinary requirements that must be met to ensure the needs of the project are catered to.

By far, the biggest hurdle for me is to make sure that WordPress is set up in such a way that it’s as easy as possible for clients to edit their content. That’s the whole point after all, right? Publicly facing, WordPress has a stigma of being a blog engine. I say stigma because being known as a blog engine does nothing to attribute to WordPress’ extensibility and rapid transformation into a full blown CMS. Besides the obvious solution of installing a CMS-facilitating plugin such as Pods, WordPress has plenty of functionality baked right in to bring your sites to the next level.

get_extended() and its unique place in WordPress

On a recent client project, I stumbled upon a feature of WordPress that seems to go unnoticed by many WordPress fans. WordPress has a built in “more” feature that allows content editors to flag a point within the copy of a Page or Post to bisect it. This flag is used by many templates, and comes into play when pulling excerpts of posts when the official excerpt field is left blank.

Since there’s an excerpt field built into every Page and Post, I’ll often suggest to clients that they should instead take a bit of a different approach to take advantage of these built in features. Excerpts are a great way to write very specific copy to be used only as an excerpt throughout the site, instead of adjusting the actual on-page copy to serve a dual purpose. While that handles the excerpt areas, it in part leaves the <!--more--> in an awkward place — how does that come in to play if the client is actively using the excerpt text area?

That’s where get_extended() comes into play. Checking out the Codex page on the function, we can see in the description that the function “gets extended entry info”. But what does that mean? Checking things out in a bit more detail, we can see that this function returns an array of post content. The first array value consists of the copy before the <!--more--> flag, and the second value holds everything after. This really opens up some doors by allowing your design to include different styles on each section of page content. For example:

<?php $pagecopy = get_extended( $post->post_content ); ?>
<div class="intro">
	<?=wpautop( $pagecopy['main'] )?>
<!-- /intro -->
<div class="entrycopy">
	<?=wpautop( $pagecopy['extended'] )?>
<!-- /entrycopy -->

Using that snippet allows us to wrap each part of the post copy in different elements, facilitating alternate styles for an ‘intro’ copy block. This came in really handy on a recent project that relied heavily on SEO, and taking this approach allowed for fine grained control over what copy appears where on the website when used in conjunction with the official excerpt text area for each page or post.

Why not just use…

The entire point of taking an approach such as this is for the benefit of the client. Sure, we could use a plugin (or even out of the box custom fields) to replicate this functionality, but we’re all designers & developers. Taking a passive angle here allows the client to understand why things are happening the way they are without having to understand how WordPress and PHP works.

On top of that, it gives the designer another level of control over the front end by including the_excerpt() or <?=wpautop($pagecopy['main'])?> at various places throughout the website.

One of the great things about WordPress is it’s ability to adapt to your needs in just about every circumstance. With that, though, comes numerous solutions to the same ‘problem’ — this is one of those cases. Please take it for what it is, but I hope it helps you on at least one of your future projects!