Tweaking WordPress Defaults


WordPress is one of the most popular website platforms on the Internet, and is the platform of choice for most of our clients. One of the great things about WordPress is its flexibility and customizability. There are a lot of ways to modify WordPress—typically through plugins or theme functions.

As a CMS solution, WordPress has many defaults in place that allow you to get your website online as quickly as possible. You can literally get a WordPress site up and running in minutes! What I wanted to touch on with this post are some of the small tweaks I like to apply to most of the sites I work on.

As with any WordPress customization, your existing plugins/theme may have functionality that mirrors or even overrides these, so keep that in mind when applying these to your site.

All of the below snippets can either be added to the functions.php file in your theme, or you can create a custom plugin to implement this code.

Excerpt Length

One of the things that is set to default right out of the box is the excerpt length. Most WordPress sites use the excerpt function to show a small preview of a post, for example on a front page or blog listing page.

By default, this is set to the first 55 words. You can make it shorter or longer to meet your needs. For example, if you want to change all excerpts to 20 words, you can use the following:

[php]// Edit the length of the excerpts
function custom_excerpt_length( $length ) {
return 20;
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’ );[/php]


Another one of the WordPress defaults I like to change is how ellipses are displayed. You’ll see this occur after your excerpt, provided the content of your post is longer than the excerpt length. The default is […], of which I’m not a big fan.

I like to change this to the standard ellipses by using the following:

[php]// Change default ellipses
function custom_excerpt_more( $more ) {
return ‘…’;
add_filter( ‘excerpt_more’, ‘custom_excerpt_more’ );[/php]

YouTube Embeds

A number of our clients use the auto-embeds (oEmbed) feature in the WordPress editor to add YouTube videos to their sites. One of the things we’re often asked is how to disable recommended videos from displaying once the video is done playing, as sometimes videos from competitors or questionable content is shown.

In order to reset the YouTube video to the beginning after playing, you can use the “rel=0” parameter in YouTube. To automatically append this to embedded YouTube videos, you can use the following:

[php]// Add reset parameter to oEmbed
function custom_oembed_reset( $html, $url, $attr, $post_id ) {
if ( strpos ( $html, ‘feature=oembed’ ) !== false )
return str_replace( ‘feature=oembed’, ‘feature=oembed&rel=0’, $html );
return $html;
add_filter( ‘oembed_result’, ‘custom_oembed_reset’, 10, 4 );[/php]

Dashboard Notes

While this isn’t technically changing a default, one of the things we like to include in our sites is a small box on the WordPress dashboard to keep helpful notes. This usually includes things like recommended image sizes for different sections, custom shortcode usage, or other handy tips.

[php]// Dashboard Notes
function custom_dashboard_help() {
echo ‘<p>====================</p>’;
echo ‘<p>Content goes here</p>’;
echo ‘<p>====================</p>’;

function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget( ‘custom_help_widget’, ‘Content Notes’, ‘custom_dashboard_help’ );
add_action( ‘wp_dashboard_setup’, ‘my_custom_dashboard_widgets’ );[/php]

Show Post Counts on Dashboard

One of the most useful features of WordPress is the ability to add different types of content by using Custom Post Types. I often find it handy to have a box on the dashboard which displays all of the current counts of published posts of all types. This code will add the counts to the “At A Glance” box on the dashboard. Just make sure this is loaded after your custom post types have been registered.

[php]// Add to Dashboard -> At A Glance
function custom_add_cpt_to_dashboard() {
$showTaxonomies = 1;
// Custom taxonomies counts
if ( $showTaxonomies ) {
$taxonomies = get_taxonomies( array( ‘_builtin’ => false ), ‘objects’ );
foreach ( $taxonomies as $taxonomy ) {
$num_terms = wp_count_terms( $taxonomy->name );
$num = number_format_i18n( $num_terms );
$text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $num_terms );
$associated_post_type = $taxonomy->object_type;
if ( current_user_can( ‘manage_categories’ ) ) {
$output = ‘<a href="edit-tags.php?taxonomy=’ . $taxonomy->name . ‘&post_type=’ . $associated_post_type[0] . ‘">’ . $num . ‘ ‘ . $text .'</a>’;
echo ‘<li class="taxonomy-count">’ . $output . ‘ </li>’;
// Custom post types counts
$post_types = get_post_types( array( ‘_builtin’ => false ), ‘objects’ );
foreach ( $post_types as $post_type ) {
if($post_type->show_in_menu==false) {
$num_posts = wp_count_posts( $post_type->name );
$num = number_format_i18n( $num_posts->publish );
$text = _n( $post_type->labels->singular_name, $post_type->labels->name, $num_posts->publish );
if ( current_user_can( ‘edit_posts’ ) ) {
$output = ‘<a href="edit.php?post_type=’ . $post_type->name . ‘">’ . $num . ‘ ‘ . $text . ‘</a>’;
echo ‘<li class="page-count ‘ . $post_type->name . ‘-count">’ . $output . ‘</td>’;
add_action( ‘dashboard_glance_items’, ‘custom_add_cpt_to_dashboard’ );[/php]

Thanks for reading!

Credit to the original authors of these snippets.
Current WordPress version as of writing: 4.2.2

Contact Us

Leave a Reply

Your email address will not be published. Required fields are marked *