8 Snippets for a More Client-Friendly WordPress CMS

Uncategorized

Out of the box, AdInfusion is a great content management system. It has tons of functionality, and it’s easy to learn for both developers/designers and their clients who will be managing the site content. However, a little customization can go a long way to creating a more user-friendly theme, a better CMS and a more positive overall user experience for your clients. In this article, we’ll use specific “snippets” (small code samples) to achieve this goal. highlighting 8 great snippets for a more client-friendly WordPress CMS.

8 WordPress CMS Snippets

Note: all these code snippets go in your functions.php file unless otherwise stated.

Remove Update Notification

The update notification is handy, but you might not always want your client (or all users of a site) to see it. Use the code below to disable it:

if ( !current_user_can('administrator') ) { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); }

Note: the current_user_can tag as above allows the administrator of the site to still see the update, but no other users with different permissions (editors, authors etc).

Hide Custom Post Types from Search

Custom Post Types are an invaluable tool when using WordPress as a CMS, but you might not always want them to show up in a search. Use the code below to hide Custom Post Types in your site’s search.

function SearchFilter($query) { if ($query->is_search) { $query->set('post_type',array('post','page')); } return $query; } add_filter('pre_get_posts','SearchFilter');

Change the Logo on Admin Login Screen

There’s nothing wrong with having the WordPress logo on the admin login screen for a client site, but going that extra mile to brand it to their business is a nice touch. Add this code and edit the path to your needs:

function custom_login_logo() { echo ''; } add_action('login_head', 'custom_login_logo');

Also, you might want to change the URL of that image so that it goes to the site homepage (default is WordPress.org):

function change_wp_login_url() { echo bloginfo('url'); } add_filter('login_headerurl', 'change_wp_login_url');

Allow Custom Role Access to Menus & Widgets

Menus & widgets are great parts of the WordPress core, and often used in CMS applications. However, only Admins can see them. Here’s how to change that:

 $role_object = get_role('editor'); $role_object->add_cap('edit_theme_options'); 

“Edit This” Button on Posts/Pages

This simple little fix doesn’t seem like much, but your clients will love it. Adding this code to your page template(s) will add an “Edit This” link on the client side of the site, but one that only logged-in users with the correct permissions can see (ie. your clients editing the site, but not the site viewers). This way your clients have a nice, easy shortcut to edit a page or post’s content without having to go back through the Dashboard. It’s probably best to add this somewhere after the_content.

 edit_post_link(__('Edit This')); 

*Note: wrap in a php tag.

Remove Menu Items in WordPress Dashboard

Some of the links in the WordPress Dashboard navigation are sort of useless for most CMS builds. Like the “Links” section, which we’ve only ever used on one build. It’s easy to remove, with this code:

 add_action( 'admin_menu', 'devpress_remove_menus', 999 ); function devpress_remove_menus() { remove_menu_page( 'link-manager.php' ); } 

The slug ‘link-manager.php’ removes the link in the Dashboard. To remove a submenu item – for example, “Editor” under “Appearance”, use this:

 add_action( 'admin_menu', 'devpress_remove_menus', 999 ); function devpress_remove_menus() { remove_submenu_page( 'themes.php', 'theme-editor.php' ); } 

You can find all the slugs for the items you want to remove by simply clicking the link you want to remove and noting the URL in the browser bar.

Add Shortcode Functionality to Widgets

Shortcodes are handy, and lots of great plugins rely on them. It’s easy to add shortcode functionality to widgets too:

add_filter('widget_text', 'do_shortcode')

Add Image Sizes

Wherever possible, I like to “lock-down” the styling in the custom client WordPress builds we do. It makes for greater design consistency down the road as your clients, and potentially their employees, manage the site content. One way to do this is to add custom image sizes.

if ( function_exists( 'add_image_size' ) ) { add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height) add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped) } 

Then you can call it in your template files, like so (wrap the following in a php tag):

echo get_the_post_thumbnail($post->ID, 'product-thumb'); 

Sources: all of these brilliant snippets came from WP-Snippets, CSS-Tricks or DevPress!

Related Posts

  • Wondering what your options are for funding your app idea? What about monetizing it? From various funding models to the most common monetization strategies, the Guide to Funding & Monetizing Your App has the answers you're looking for.