Web Analytics

Serious WordPress Tweaks: Custom Excerpts, Multisite Widgets and Contributor Uploads

by Jason Unger, Founder

You don’t have to be a hard-core programmer to make WordPress do something out of the box. It can be tweaked to work exactly how you’d like, if you know what you’re doing or what needs to be changed.

It’s Friday, so let’s do a little round-up of some of my favorite WordPress tweaks (coincidentally, all of which we’ve used in recent projects).

How to Display Two Different Excerpt Lengths

If you find yourself in a situation where you’re running multiple WordPress loops and you’d like them to output different excerpt lengths or formatting styles, you simply need to create a function for a new custom excerpt. From the WordPress Forums:

function get_the_popular_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" ([.*?])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 40);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
return $excerpt;
}

This example will show an excerpt of 40 characters instead of the default 55 words. Echo get_the_popular_excerpt() to display it in your loop.

Register Multisite Widget Areas for the Main Site Only

WordPress Multsite allows you to tweak the look and feel of the main site from the sub-sites, and oftentimes that’ll include the widget areas available in each one. If you’re looking to make a widget area available only for the main site and not the sub-sites, here’s what you edit in your functions.php file:

global $blog_id;
if( $blog_id == '1' ) {
REGISTER YOUR WIDGET AREA HERE
}

Allow Contributors to Upload Files

WordPress permissions are pretty good for most cases, but if you want to allow your “Contributors” to upload files to their posts and to the site, it’s an easy change again in your functions.php file:

if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}

About Jason Unger

Jason Unger is the Founder of Digital Ink. He built his first website on Geocities, and hasn't looked back since. Digital Ink tells stories for forward-thinking businesses, mission-driven organizations, and marketing and technology agencies in need of a creative and digital partner.

Other Stories You May Like

What’s your story?

Let’s share it with the world.

Let’s Do This

Close Window
All the Cool Kids are Doing it

Sign Up for the Digital Ink Newsletter

All the cool kids are doing it.