How To Prevent Other To View Your Wordpress Folders Content

If you browse to your Wordpress Folders such as wp-content, you may see something like this:

wp-folder

That means, others can easily know your installed themes and plugins, which is very dangerous and easily to hacked by hackers.

There are two ways to solve this problem. The first method is create an empty index.php file and put under the folder. The other method is edit your .htaccess file, add an entry “Options -Indexes” (withour quotes).

The second method is a more advance and secure method as you need to put index.php file in each folders if you use the first method.

Easily Reset Your Wordpress’s Admin Pasword

How often are you change your Wordpress admin’s password? What happen if you forgot your Wordpress admin account password? Do you need to delete the databse and recreate it?

Although you cannot recover your current admin’s password, but it is not neccessary to delete the database and recreate it. You can simply replace it with a new password. Here, i will show you a very simple method to replace the password.

First of all, open your favorite code editor, or simply Notepad if you don’t have any. Then, place these code into the file and save it as reset.php.

<?php
require('./wp-blog-header.php');

global $wpdb;
$password = '12345';    //change this to your desired password.
$admin_login = 'admin';        //your Wordpress admin username.

$wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$password') WHERE user_login = '$admin_login'");
?>

You can replace the ‘12345‘ with your desired password and ‘admin’ with your admin account username. After that, upload the reset.php file to your Wordpress root folder.

Then, go to your browser and type “http://your-domain.com/reset.php“. Done! You can now login with your new admin password.

Note: Please delete the reset.php file from the server after you reset your password.

How To Delete Wordpress Post Revisions

Wordpress introduce post revision feature since version 2.6. It helps us to keep revisions of our posts and we can restore to previous revisions anytime.

Although this is a great feature, but what happen if you accumulate too many revisions? Probably your server will takes longer time to query and processes database requests. That means, your blog will load slower and your visitors may wait longer before the content comes out.

So, we may want to delete unwanted post revisions. This can be done by logging to phpMyAdmin and execute the SQL command, or use a plugin.

SQL command to delete post revisions

Here, i would assume you know how to login to your phpMyAdmin and know how to execute SQL command. So, simply run this SQL command and all stored post revisions will be deleted.

DELETE FROM wp_posts WHERE post_type = “revision”;

Use Delete Revision Wordpress plugin

This is an easier method. Just download the Delete Revision plugin and go to your Settings->Delete-Revision to delete them.

Press the Check Redundant Revision button and the plugin will automatically search for post revisions.

Remember, both the SQL command and delete-revision plugin will delete all your post revisions, and you are not allow to choose which revesion to be deleted. So, please make sure you won’t regret after delete them!

Tips: You can turn off post revision feature by go to your wp-config.php and add define(’WP_POST_REVISIONS’, false); before the closing ?> tag.

Create A Latest Post Section At The Beginning Of Each Post

I get this idea from SmashingApps. They created a latest article section at the top of each article. You may refer to the screenshot below:

This will make sure those readers who reach your blog through search engine or referer will have a chance to read the latest article. So, how are you going to add this section? Do you need any plugin to do so? No, you don’t need any plugin to add this section. Simply follow the tutorial below, and i will create a custom function for you.

  1. First, open your template’s functions.php using any text editor.
  2. Place this code at the end of the file. (Before “?>“)
    /* Get latest post */
    function get_latest_post($pre="You maybe interested in our latest article") {
    global $wpdb;
    $sql = "
    SELECT P.ID, P.post_title
    FROM $wpdb->posts P
    WHERE P.post_status = 'publish'
    AND P.post_type = 'post'
    ORDER BY P.ID DESC
    LIMIT 1
    ";
    $post = $wpdb->get_row($sql);
    $ret = $pre;
    $ret .= '<a href="'. get_permalink($post->ID).'" title="'. $post->post_title .'"> '. $post->post_title .'</a>';
    echo $ret;
    }
  3. Basically, the code will query the latest published post, get the permalink and post title, and then append it with some text (the default is “You maybe interested in our latest article“).
  4. Open your single.php and place this code before the “entry” div.
    <div id="latest-post">
    <p><?php get_latest_post("You may want to read our latest article"); ?></p>
    </div>
  5. You may change the “You may want to read our latest article” to any text that you want. Leave it blank and you will use the default setting.

You may call this function anywhere in your article or change the style through your template’s stylesheet.

3 Methods To Exclude Wordpress Categories In A Post

Sometimes, we may want to exclude some categories from display in our main page or sidebar. There are a lot of methods to exclude these categories. Here i would like to share 3 types of different method to do so.

Use Wordpress Category Visibility Plugin

This plugin will let you to exclude any tag and category at different pages. For example, you can exclude selected category in the front page, search results, archives, and feeds. Simply activate the plugin and go to your Manage->Category Visibility to manage them. (There are some users who claim this plugin may has conflict with other Wordpress plugins.)

wp_list_categories() template tags

You may use this template tags to list out all categories at your website’s navigation bar or your sidebar. The template tags tutorial website actually teach us how to include or exclude categories by adding parameters when we call this template tags.

Hack the default widgets.php

I read this tutorial from Simple Solution For smart People website. You need to make a backup of wp-includes/widgets.php file before proceed.

  1. After you backup the file. Open it using any text-editor and try to look for function wp_widget_categories. I am using Wordpress 2.6.x and it is around line 703. This is the only function that you need to modify.
  2. Find the following line:
    $d = $options[$number]['dropdown'] ? '1' : '0';

    Add $exclude = ‘17′; below this line. You may replace 17 with the Category ID that you want to exclude. You may exclude more than one category by adding a “,” between the number.

  3. Next, look for
    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);

    And replace it with

    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'exclude' => $exclude);

Done. You can change the “17″ to any category ID that you want to exclude anytime. I had pasted my codes at the end of this tutorial, in case you don’t understand my tutorial.

function wp_widget_categories($args, $widget_args = 1) {
    extract($args, EXTR_SKIP);
    if ( is_numeric($widget_args) )
        $widget_args = array( 'number' => $widget_args );
    $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    extract($widget_args, EXTR_SKIP);

    $options = get_option('widget_categories');
    if ( !isset($options[$number]) )
        return;

    $c = $options[$number]['count'] ? '1' : '0';
    $h = $options[$number]['hierarchical'] ? '1' : '0';
    $d = $options[$number]['dropdown'] ? '1' : '0';
    $exclude = '17';

    $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']);

    echo $before_widget;
    echo $before_title . $title . $after_title;

    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'exclude' => $exclude);

    if ( $d ) {
        $cat_args['show_option_none'] = __('Select Category');
        wp_dropdown_categories($cat_args);
?>

Hope you enjoying reading my tutorial. Please choose any method that suit you.

Page 1 of 212»