Disable Post Revisions in WordPress to reduce Database Size


Post revisions is a great feature that WordPress has to offer but for some users it might not be the best option. For users who have limited database space, or for users creating WordPress as a CMS where they don’t need autosave, they can simply disable Post Revisions feature in WordPress by following this tutorial. By reducing the database size, you can also speed up your site.

Open wp-config.php located in your WordPress root directory and add the following code:

define('AUTOSAVE_INTERVAL', 300 ); // seconds
define('WP_POST_REVISIONS', false);
 This code will disable all future revisions to be saved and it will also increase your autosave interval from 60 seconds to 300 seconds, so it means your post will be autosaving every 5 minute instead of every minute.

The above code, will not delete your past revisions that are already saved in your database. To delete all previous revisions, you will need to visit PHPMyAdmin and run the following SQL query.

DELETE FROM wp_posts WHERE post_type = "revision";
 This should disable Post revisions and delete all previously saved post revisions stored in your Database.
Advertisements

How to add excerpt on a Page in WordPress without plugin


To add an excerpt field in WordPress Pages like we have in Posts, just paste the following code to your functions.php and have fun !!

add_post_type_support( 'page', 'excerpt' );

Get Image from Post or Page


Add the following function in function.php which is present at the root of theme folder.

function catch_that_image()
{
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];

if(empty($first_img))
{ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}

Just call the function catch_that_image(), wherever you need to get the image from the article.
e.g.

<img src="<?php echo catch_that_image();?>" width="75" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" align="left" hspace="5" />

Difference Between Posts and Pages in WordPress


Often WordPress beginners get confused between posts and pages. By default, WordPress comes with two content types, posts and pages. As a beginner, you are probably wondering what is the difference between them? It seems to have similar fields in the dashboard. It seems to look the same on the website. Why do I need both? When should I use posts? When should I use pages? In this article, we will explain the difference between posts vs. pages in WordPress.

Posts

If you are using WordPress as a blog, then you will end up using posts for majority of your site’s content. Posts are content entries listed in reverse chronological order on your blog’s home page. Due to their reverse chronological order, your posts are meant to be timely. Older posts are archived based on month and year. As the post gets older, the deeper the user has to dig to find it. You have the option to organize your posts based on categories and tags.

Because WordPress posts are published with time and date in mind, they are syndicated through the RSS feeds. This allows your readers to be notified of the most recent post update via RSS feeds. Bloggers can use the RSS feeds to deliver email broadcasts.

Posts encourage conversation. They have a built-in commenting feature that allows users to comment on a particular topic. You can go to your Settings » Discussion to turn off comments on older posts if you like. Continue reading