How to Create New Permalink Rules

In WordPress, you can easily create a pretty URL by going to the Settings -> Permalinks section and update the permalink structure. However, if you are creating your own themes or plugins, there are times when you need to create a custom permalink structure.

For example: you want to implement a permalink: http://your-site.com/movies/1 which translates to http://your-site.com/index.php?movies=1.

Here’s how you do it:
Continue reading

How to Change the Font in HTML Editor In WordPress 3.3

The HTML editor in WordPress 3.3 uses monospace font, which is not really friendly to the eyes. Here’s how to change the font to, say, verdana.

1. Open your theme’s functions.php file.

2. Copy and paste the following code:

add_action( 'admin_head-post.php', 'wpdb_fix_html_editor_font' );
add_action( 'admin_head-post-new.php', 'wpdb_fix_html_editor_font' );
 
function wpdb_fix_html_editor_font() { ?>
    <style type="text/css">
        #editorcontainer #content, #wp_mce_fullscreen, .wp-editor-area {
            font-family: Verdana,Arial,sans-serif!important;
        }
    </style>
<?php }

3. Save the functions.php file back to the server.

That’s it.

How to Remove the Width and Height Attributes From WP Image Uploader

If you upload images via the WordPress image uploader and insert it into your post, it will include the image width and height attribute in the html <img> tag. Here’s what it will look like.

<img src="path/to/your/image" width="123" height="456" class="aligncenter size-full" alt="" title=""/>

In most cases, this is absolutely alright. However, if you are using a responsive theme or are dealing with responsive web design, the “width” and “height” attribute will be a major roadblock that you need to get rid of.

Here’s how you can do it.
Continue reading

How to Edit The Excerpt

Changing the Excerpt length

Paste this code to the functions.php of your theme folder.

function custom_excerpt_length( $length ) {
	return 30; //change this number to determine the number of words returned
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Adding “Read More” link after the excerpt

function new_excerpt_more($more) {
        return '... <span class="read-more"><a href="'. get_permalink($post->ID) . '">Read more  &raquo;</a></span>';
       //if you just want to remove the [...] after the excerpt, use 'return '';'
}
add_filter('excerpt_more', 'new_excerpt_more');

That’s it.

How to Remove Miscellaneous Widgets From WP Dashboard

widgets-mainWhen you are logged into your WordPress dashboard, you may have noticed that there are many useless widgets that you don’t even bother looking at it, but it is taking up a long time to load. While you can hide them using the screen options, it is better to remove them for good and prevent them from taking up your precious load time.

Here is how you remove them:

In your functions.php, copy and paste the following code:

add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
function remove_dashboard_widgets() {
	global $wp_meta_boxes;
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}

What the above code does is to unset the widgets from the dashboard array so that they won’t get loaded in the frontend. If you want to preserve any of the widgets, simply remove them from the above code. Continue reading

WordPress 3.1 Very Slow? Disable The Admin Bar [Quick Tip]

Ever since I upgraded to WordPress 3.1, I found that getting around in the admin area becomes very slow. Typing a post in the text editor is extremely laggy and becoming more of a nightmare. Apparently. this was due to the admin bar taking up the system resource. One good way is to disable it for good.

Here’s how you can disable the admin bar:
Continue reading

Limit The jQuery Lazy Load Plugin to Operate Only In The Content Area

lazy-dazyIf you have noticed, one of the way that highly-trafficked site save bandwidths is to use a lazy load plugin. What this lazy load plugin does is to load the images only when they become visible on the screen. Any images below the visible screen will not be displayed. This is also known as on-demand loading.

In WordPress, there are several lazy load plugins that you can use. One of my favorite is the jQuery Image Lazy Load plugin, simply because it just works the moment you activate it. No configuration is required.
Continue reading

How to Make Disqus Notify the Post Author When a New Comment Is Posted?

By default, in a multi-authors blog, you can get WordPress to notify the post author when a new comment is posted. To do this, you just have to update the “Email me whenever” field in “Settings -> Discussion”.

comment-email-me

Now if you are using Disqus as your comment system, you will find that it won’t notify the author when a new comment is posted. Instead, it will only notify the moderators.

To fix this, go to the Disqus-Comment-System folder in the Plugins directory. Open the disqus.php in a text editor. Scroll down to line 289 where you see the following:

$comment_id = $commentdata['comment_ID'];
update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
update_comment_meta($comment_id, 'dsq_post_id', $comment->id);

Add in the line “wp_notify_postauthor($comment_id);” so that it becomes:

$comment_id = $commentdata['comment_ID'];
update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
wp_notify_postauthor($comment_id);

Save, upload and replace the file back to the server.

That’s it. It should notify your authors whenever there is a new comment.