Developing a full fledge WordPress website and wondering on that a huge numbers of plugins you would be requiring to make it complete, don’t worry it can’t be a way all the time as there is Plan B also available which will help reduce your job: using WordPress snippets. Snippets are the short codes which you can use directly in your theme files – totally as per your requirement. Don’t worry also if in case you would be thinking that “hey, I am a WordPress beginner then what?” don’t worry on this as this short code requires very less of your technical knowledge – all important with it is the right placements of these codes in your theme files.
Page excerpt
The snippet will add excerpts for pages. All you require is to place the following code in your themes functions.php file and you are done.
1 |
add_post_type_support( 'page', 'excerpt' ); |
Highlight author comments
Blog authors always want that their comments to look difference from that of the readers as it highlight and bring more values in reading. Using the snippet (below) will help you achieving the same. Find the list-item in the comment.php template file and add this in the class-tag.
1 2 3 4 |
<?php if (1 == $comment->user_id) echo 'author'; ?> |
Reset your password
This would be a biggest nightmare for you if not able to reset your password especially when you can’t use the “forgot password” function. Insert this snippet into a phpMyAdmin Sql-window.
1 |
UPDATE `wp_users` SET `user_pass` = MD5('NEW_PASSWORD') WHERE `wp_users`.`user_login` =`YOUR_USER_NAME` LIMIT 1; |
Empty Trash Automatically
If you wish to have your WordPress trash to get empty automatically, then just add the following line of codes to the wp-config.php-file.
1 |
<?php define('EMPTY_TRASH_DAYS', 5 ); ?> |
Image Custom Field
If you want to call the custom field for an image source, then use the following snippet.
1 2 3 4 5 6 |
<?php $image = get_post_meta($post->ID, 'image', TRUE); ?> <?php if($image) { ?> <img src=" <?php echo $image; ?> " alt="Alt Text" /> <?php } ?> |
Add Taxonomies
The snippet will allow you to create your own tag-section for your custom post types.
1 2 3 4 5 6 |
<?php function my_taxonomies() { register_taxonomy('my_tags', 'post', array('label' => 'My Tags')); } add_action( 'init', 'my_taxonomies'); ?> |
Remove meta generator
It would always be advisable to remove the “meta generator tag” which WordPress generates in your WordPress header. Use either of following code in your header.php template.
1 |
<?php remove_action('wp_head', 'wp_generator'); ?> |
OR
1 |
<meta content="My Custom Generator | <?php bloginfo(’version’); ?>" name="generator"> |
Disable WordPress Update
To avoid client messing up with the whole of WordPress website, just add this to disable WordPress update function by adding this into your themes functions.php template.
1 2 3 |
<?php add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) ); ?> |
Add a Dashboard Widget
As soon as you login into your WordPress Dashboard, the first thing you will notice that it has been filed with number of widgets. Using this code will allow you to add your own widgets, just add this code to functions.php.
1 2 3 4 5 6 7 8 9 |
<?php function your_dashboard_widget() { ?> <h3>Hello Wordpress user!</h3> <p>Fill this with HTML or PHP.</p> <?php }; function add_your_dashboard_widget() { wp_add_dashboard_widget( 'your_dashboard_widget', __( 'Widget Title!' ), 'your_dashboard_widget' ); } add_action('wp_dashboard_setup', 'add_your_dashboard_widget' ); ?> |
Change footer-text in WP Admin
Using the code will change the text in the bottom of the WP admin pages.
1 2 3 4 5 6 |
<?php function remove_footer_admin () { echo 'My footer text. Thank you <a href="http://wordpress.org">Wordpress</a> for giving me this filter.'; } add_filter('admin_footer_text', 'remove_footer_admin'); ?> |
Remove meta-boxes
Using this snippet, you can remove the meta-boxes you don’t use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php function remove_meta_boxes() { # Removes meta from Posts # remove_meta_box('postcustom','post','normal'); remove_meta_box('trackbacksdiv','post','normal'); remove_meta_box('commentstatusdiv','post','normal'); remove_meta_box('commentsdiv','post','normal'); # Removes meta from pages # remove_meta_box('postcustom','page','normal'); remove_meta_box('trackbacksdiv','page','normal'); remove_meta_box('commentstatusdiv','page','normal'); remove_meta_box('commentsdiv','page','normal'); } add_action('admin_init','remove_meta_boxes'); ?> |
Enable debug mode
Add this to your wp-config.php and you will be able to debug your WordPress blog if something went wrong.
1 2 3 4 |
<?php if ( isset($_GET['debug']) && $_GET['debug'] == 'debug') define('WP_DEBUG', true); ?> |
Change Admin logo
Give your Admin panel a brand look just like whole of your blog; change the logo in the Admin panel with an image of your choice by using this snippet.
1 2 3 4 5 6 7 8 |
<?php function custom_admin_logo() { echo '<style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/admin_logo.png) !important; } </style>'; } add_action('admin_head', 'custom_admin_logo'); ?> |
Remove Pages Columns
The code will allow you to remove a column from pages.
1 2 3 4 5 6 7 |
<?php function remove_pages_columns($defaults) { unset($defaults['comments']); return $defaults; } add_filter('manage_pages_columns', 'remove_pages_columns'); ?> |
Change role capabilities
WordPress comes with several pre-defined role capabilities, like Author, Contributor or Administrator. In order to change these, just add the following to functions.php and you can create your own and customized it as per you like.
1 2 3 4 5 6 7 8 |
<?php # Get the user role # $edit_contributor = get_role('contributor'); # Contributor can upload media # $edit_contributor->add_cap('upload_files'); # Contributor can no longer delete posts # $edit_contributor->remove_cap('delete_posts'); ?> |
Photo Credit: cogdogblog via photopin cc