WordPress is an absolute favorite among developers and bloggers because it is super flexible and customizable. With thousands of useful plugins, you can create an amazing web page with the outstanding user experience. Not to forget that even the novices will be able to find their way around and learn how to use it in no time. Check out the complete WordPress tutorials to take your site to next level.
WordPress Hacks for Developers
But is there a way to make your blog stand out? These fifteen WordPress hacks for a developer will help you create a functional web page that will look the way you want it to.
1. Quick Facebook Sharing
Social media is crucial for getting more audience to your website. The best way to increase your traffic is to make Facebook sharing easy. Luckily, there is a hack which will create a share on Facebook button on your website.
Find single.php file which is located in your WordPress theme and then paste this code:
<a href="https://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>" target="blank">Share on Facebook</a>
2. Login Without an Error Message
If you have a login option on your blog, you already know that once user types in an incorrect username or password, there is an error message on the page. Hackers can try to break into your web page by guessing passwords and/or usernames so the smartest thing you can do in order to protect your blog is to remove the error message because they will not know which piece of information they got right.
Remove the error message with this line of code:
add_filter('login_errors',create_function('$a', "return null;"));
3. Visual or Text Mode in Classic Editor
Some users prefer visual editor while others are fans of the good old HTML text editor. It all comes down to your personal preferences when it comes to posting on your WordPress page. But switching between the editors can be annoying so the best way to make this easier is to choose one to be your default.
This is the code you need to enter in your functions.php file:
For Visual Editor:
add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
For Text Editor:
add_filter( 'wp_default_editor', create_function('', 'return "html";') );
4. Add Your Logo
This tip is great for developers who create or maintain their client’s blogs in WordPress. It will allow you to add your own logo to the page straight from the code. The visitors will know that you made the page and there will be a possibility of expanding your business which is always helpful.
Enter this code:
add_action('admin_head', 'custom_logo');
function custom_logo() {
echo '
<style type="text/css"><!--
#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.jpg) !important; }
--></style>';
}
5. Latest Blog Posts
If you want to group and display the newest blog posts on your WordPress page so the visitors will have a better view of the topics you have covered lately, there is a hack for that. This will make your page cleaner and more user friendly.
If you want more posts on your front page, change 5 in showposts=5 to any number you like.
<?php query_posts($query_string . '&showposts=5' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="story">
<div class="story-content">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
6. No Display of WordPress Version
When a hacker knows the version of WordPress you are using for your blog, it is easier to find holes and errors they can exploit for breaking into your page and stealing valuable data. You have probably noticed that WordPress will automatically display the current version but you can easily remove it from your page.
This is the code you need:
<?php
function remove_wp_version(){
return '';
}
add_filter('the_generator', 'remove_wp_version');
?>
7. Choose RSS Publishing Time
If you have been using WordPress for some time now, you are aware that some mistakes can sneak into a post and you might publish it unknowingly. Yes, you can always fix a typo as soon as you see it but the first version of the post will end up in your followers’ RSS feed.
This simple line of code will hold back the post from RSS feeds as long as sixty minutes in case you want to edit something later:
function publish_later_on_feed($where) {
global $wpdb;
if ( is_feed() ) {
$time_now = gmdate('Y-m-d H:i:s');
$time_delay = '15'; // integer
$time_span = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
$where = " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$time_now') > $time_delay ";
}
return $where;
}
add_filter('posts_where', 'publish_later_on_feed');
8. Custom Footer Text
When making a WordPress site for a client, it is quite important to represent their brand properly. You can add a touch of personality by including a custom footer text on the dashboard beside their company’s logo.
Click on functions.php and paste this line of code:
function remove_footer_admin () {
echo "Your own text";
}
add_filter('admin_footer_text', 'remove_footer_admin');
9. Lower Number of Revisions
Revisions are a useful tool that will allow you to access previous versions of the content you posted on your website. Even though WordPress is capable of saving every single revision, having a large number of them can make you confused. It is best to lower that number and keep the last couple of versions available to you.
If you want to use this hack, open wp-config.php, paste this, and enter the number you want:
define( 'WP_POST_REVISIONS', 3 );
10. Better Photographs
Are you a photographer and you use your blog in order to showcase your work? Then you have noticed that WordPress will slightly lower the quality of your images so they will not look as detailed as the original version you have on your computer. But there is a hack that will go around this problem and allow you to upload your work in its full glory.
Here it is:
add_filter( 'jpg_quality', 'high_jpg_quality' );
function high_jpg_quality() {
return 100;
}
11. Enable Shortcode in Widgets
WordPress widgets are not capable of recognizing shortcode but their usefulness is undeniable. They will shorten up the length of long code lines and make your job as a developer a lot easier. Widgets will be able to recognize shortcode if you paste this into functions.php file:
add_filter('widget_text', 'do_shortcode');
12. Remove Widgets from Certain Pages
Everyone loves widgets because they give you extra options and make your WordPress page look better. But sometimes you need a clean design for certain areas and widgets might make the page look cluttered with unnecessary information and links. If you don’t want to edit the entire backend of a page, this simple line of code will remove them without too much effort.
For example, open the functions.php file and paste the below code to disable widgets in home page:
<?php
add_filter( 'sidebars_widgets', 'disable_all_widgets' );
function disable_all_widgets( $sidebars_widgets ) {
if ( is_home() )
$sidebars_widgets = array( false );
return $sidebars_widgets;
}
?>
13. Frequency of Autosave
Autosave is a wonderful option that keeps your work secure in case your computer or browser crashes. Your text will be right there waiting for you so there is no need to panic if you are working on a long piece of text. But if you are a prolific writer who hates getting their flow interrupted every single minute with an auto save, you can change the frequency without downloading any third party software. This line of code is customizable and you can choose the exact timing.
Go to wp-config.php file, paste this, and edit it to your liking:
define( 'AUTOSAVE_INTERVAL', 45 );
14. Page Number for Search Results
If you have a large variety of content on your WordPress page, the visitors might be using the search option in order to find a particular article that interests them. The standard search engine usually does not displays the number of pages related to the search. Luckily, there is a line of code that can help you out. Open search.php file and paste this:
<h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>
15. Replace the Howdy
And finally, there is a way to customize the greeting message in the WordPress bar. If Howdy seems too casual for you and you want a formal greeting, go to functions.php, paste the code below, and change $newtitle to a message which is more fitting to your website:
function replace_howdy( $wp_admin_bar ) {
$my_account=$wp_admin_bar->get_node('my-account');
$newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}
add_filter( 'admin_bar_menu', 'replace_howdy',25 );
Leave a Reply
Your email is safe with us.