WordPress plugins are effective and easier to use. They do what they are meant to do. You can get WP plugins for almost any tweak you want to do with your site. But there are still a few tweaks that can’t be done by plugins. Or, if they could be done — plugins might build seriously more load on your site. To solve this, you can always place some PHP scripts which run into your WordPress’ site’s front-end to offer wanted results. This process doesn’t need installation of plugins and hence strengthens your site’s security and keeps bloat away.

Here is the list of some highly useful PHP scripts to use for your WordPress blog. This list is expandable and will surely expand to a larger number of scripts as time moves on. All the codes listed below are error-proof and tested by me on my blog.

Place the given PHP code in between <?php and ?>  inside your theme’s functions.php file. If there is no ending  ?> , it is recommended to place the code at the end-part of the file.

 global $wpdb;
 $wpdb->query( "
 DELETE FROM $wpdb->postmeta
 WHERE meta_key = '_thumbnail_id'
 " );

After you finished placing the code, save and update the functions.php file. Viola! You see that all featured images are gone. Now you can remove above php code from functions.php  as it is just a one time job. Please note that you will not be able to set featured images until you remove the mentioned code.

Credit: Kaiser

Redirect Author Archives to ‘About’ page

For a blog with single author, there is no need of Author archives as the same can be achieved by regular archives. It’s better suggest to redirect Author archives to your own about page. Put the following code inside your theme’s functions.php file:

add_filter( 'author_link', 'my_author_link' ); function my_author_link() {  return home_url( 'about' );  }

Here highlighted text ‘about’ is the slug at which your about page is located.

Credit: WPHub

Show Estimated Reading Time at Post Meta

Want to tell your readers, how long will it take an article to read completely? Insert the following code into right file (e.g., single.php or page.php) at the right place (above post meta and below post title) in your theme. It counts total words in an article and calculates time by estimating that on average a reader can read 200 words in a minute.

$mycontent = $post->post_content;
            $word = str_word_count(strip_tags($mycontent));
            $m = floor($word / 200);
            $s = floor($word % 200 / (200 / 60));
            $est = $m . ' minute' . ($m == 1 ? '' : 's') . ', ' . $s . ' second' . ($s == 1 ? '' : 's');

Estimated Reading Time:

  • Least reading time is 0 minutes and 1 second for blog post with almost zero words.
no words estimated time
  • A huge article may have reading time as long as half an hour:
some content

Replace the default WordPress Login Logo with your site’s custom header image

There are few plugins for that, but you can also do the same by inserting these brief lines of code to your theme’s functions.php file:

function namespace_login_style(){
if( function_exists('get_custom_header')){
        $width = get_custom_header()->width;
        $height = get_custom_header()->height;
} else {
        $width = HEADER_IMAGE_WIDTH;
        $height = HEADER_IMAGE_HEIGHT;}
    echo ''.PHP_EOL;}

Hide from readers that you are using WordPress or WooCommerce or any other Custom Frameworks

Do you use WordPress or WooCommerce or even a custom framework but still don’t want others to know what CMS platform you really use? Input the following codes in functions.php file and let no one know where you are blogging at:

function complete_version_removal(){return'';}

Limit the maximum number of post revisions stored on Database

This reduces load on your web-host by changing infinite post revision limits into a finite number. For example if you want to save no more than 10 post revisions of posts/pages in your dashboard, place the following code inside functions.php. :

if(!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS',10);

This works only if you have not already set post revisions’ limit in your WordPress installation’s wp-config.php file.

Load WooCommerce Scripts only When Needed

WooCommerce is useful, but a very heavy plugin. It enqueues its files on every page of your site, whether needed or not. By simply copying & pasting the following code into your theme‘s functions.php file, you can make sure that WooCommerce scripts load only on WooCommerce pages.

add_action('wp_enqueue_scripts', 'myown_remove_scripts');

function myown_remove_scripts(){
if ( function_exists( 'is_woocommerce' ) ) {
 //dequeue scripts and styles from not WC pages
 if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
 wp_dequeue_style( 'woocommerce-layout');
 wp_dequeue_style( 'woocommerce-smallscreen');
 wp_dequeue_style( 'woocommerce-general');
 wp_dequeue_script( 'wc_price_slider' );
 wp_dequeue_script( 'wc-single-product' );
 wp_dequeue_script( 'wc-add-to-cart' );
 wp_dequeue_script( 'wc-cart-fragments' );
 wp_dequeue_script( 'wc-checkout' );
 wp_dequeue_script( 'wc-add-to-cart-variation' );
 wp_dequeue_script( 'wc-single-product' );
 wp_dequeue_script( 'wc-cart' );
 wp_dequeue_script( 'wc-chosen' );
 wp_dequeue_script( 'woocommerce' );
 wp_dequeue_script( 'prettyPhoto' );
 wp_dequeue_script( 'prettyPhoto-init' );
 wp_dequeue_script( 'jquery-blockui' );
 wp_dequeue_script( 'jquery-placeholder' );
 wp_dequeue_script( 'fancybox' );
 wp_dequeue_script( 'jqueryui' );

Adding Support for Post Thumbnails & Custom Thumbnail Sizes

This one too goes inside theme’s functions.php :

// adding theme support for post thumbnails
add_theme_support( 'post-thumbnails' );
// adding certain sizes

 add_image_size( 'own-id', '1000', '700', false );
 add_image_size( 'another-id-here', '500', '350', true );

‘true’ and ‘false’ are answers of argument, whether to force-crop the image or not.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

10 Awesome Android Apps for Pro-bloggers

Without any doubt, Android is world’s most popular mobile operating system. Sponsored by Google, this OS has already spread its roots from casual users to hardcore code-maniacs. Bloggers and pro-bloggers are no exception. It’s highly likely to have at least one android device for any blogger who calls him/her a blogging professional. Blogging app choices for Android are fairly limited…

How to fix broken images in WordPress?

Nothing exists forever — including those images that you inserted in your blogposts from various external sources. Those who have been blogging for a long time now know the pain of such broken image links. Due to corrupt files, incorrect links, expired domains, deleted resources or whatever — your WordPress site can occasionally yield 404-errors on images — leading to…

Applications of Complex Number Analysis to Divisibility Problems

Prove that $ {(x+y)}^n-x^n-y^n$ is divisible by $ xy(x+y) \times (x^2+xy+y^2)$ if $ n$ is an odd number not divisible by $ 3$ . Prove that $ {(x+y)}^n-x^n-y^n$ is divisible by $ xy(x+y) \times {(x^2+xy+y^2)}^2$ if $ n \equiv \pmod{6}1$ Solution 1.Considering the given expression as a polynomial in $ y$ , let us put $ y=0 $ . We…

My Five Favs in Math Webcomics

Cartoons and Comics are very useful in the process of explaining complicated topics, in a very light and humorous way. Like: Source of These Cartoons Here my five most favorite math-webcomics sites. (Click on images to visit them.) 1. Spiked Math 2. xkcd 3. SMBC COMICS 4. Oh! You math! 5. Abstruse Goose Enjoy reading!

HostingRaja – One of the Best Web Hostings in India

Looking for the best hosting company in India? But, yet, don’t want to spend too much money on the hosting packages? Then, you are going to love this post, because today I am introducing HostingRaja which is, itself, one of the best web hosting providers in India. They have just surpassed all the limits of providing quality features and that’s…