WordPress Hacks accross the Web

Posted In Wordpress - By ashrith On Sunday, August 14th, 2011

Change the WordPress HTML Editor Font

One of the new feature that has been rolled out with version 3.2 is the change of the font for the HTML editor to a monoscope font which os ofcourse not so good as the previous version and isn’t so distraction free when you are trying to write.

add_action( ‘admin_head-post.php’, ‘cwc_fix_html_editor_font’ );
add_action( ‘admin_head-post-new.php’, ‘cwc_fix_html_editor_font’ );
function cwc_fix_html_editor_font() { ?>
<style type="text/css">#editorcontainer #content, #wp_mce_fullscreen
 { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; }
</style>
<?php }

This will give you a font stack of: Georgia, Times New Roman, Bitsstream Charter, Times, Serif
You can change the font to what ever you desire to.
Source:Devpress

Browser Caching with .htaccess

If your site is bogged down from so much repeat traffic? Slow page loads. This code can be added into your “.htaccess” file (located at the root of your wordpress site)
NOTE: when ever working with .htacess. keep a backup of the file.

## EXPIRES CACHING ##
ExpiresActive On
ExpiresByType image/jpg “access 1 year”
ExpiresByType image/jpeg “access 1 year”
ExpiresByType image/gif “access 1 year”
ExpiresByType image/png “access 1 year”
ExpiresByType text/css “access 1 month”
ExpiresByType application/pdf “access 1 month”
ExpiresByType text/x-javascript “access 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType image/x-icon “access 1 year”
ExpiresDefault “access 2 days”
## EXPIRES CACHING ##

Implement Maintenance Mode

If you want to work on your blog and want the traffic to be blocked from the main website, maintenance mode is the best option. Add the following code snippet to your “functions.php” with in your template folder or your theme folder.

<pre lang="php">
function maintenace_mode() {
if ( !current_user_can( ‘edit_themes’ ) || !is_user_logged_in() ) {
die(‘Maintenance.’);
}
}
add_action(‘get_header’, ‘maintenace_mode’);
</pre>

SImplify your WordPress Login URL

If you want your wordpress login URL to be short like this http://yoursite.com/login instead of http://yoursite.com/wp-login. This makes working with many authors a whole lot easier. Add the folowing code to “.htaccess

RewriteRule ^login$ http://yoursite.com/wp-login.php [NC,L]

Split Post Comments and Trackbacks

One bit of functionality which hasn’t been seen in wordpress at all is the ability to split between post comments and trackbacks. The two are entirely different and can be very confusing seeing them put together. This short bit of code should be added into your commnets.php file inside themes folder.

<ul class="commentlist">
<?php // only comments

<span style="white-space: pre;"> </span> <?php foreach ($comments as $comment) : ?>
<span style="white-space: pre;"> </span> <?php $comment_type = get_comment_type(); ?>
<span style="white-space: pre;"> </span> <?php if($comment_type == ‘comment’) { ?>
<span style="white-space: pre;"> </span> <li>//Comment code goes here </li>
<span style="white-space: pre;"> </span> <?php }
endforeach;
</ul>
<ul>
<?php // only trackbacks

<span style="white-space: pre;"> </span>foreach ($comments as $comment) : ?>
<span style="white-space: pre;"> </span> <?php $comment_type = get_comment_type(); ?>
<span style="white-space: pre;"> </span> <?php if($comment_type != ‘comment’) { ?>
<span style="white-space: pre;"> </span> <li> <?php comment_author_link() ?></li>
<span style="white-space: pre;"> </span> <?php }
endforeach;
</ul>

Source: Skyje.com

Disable theme switching

When working with clients, it can be good to keep the control of what they can do to prevent possible problems. For example, disabling theme switching can be a good idea, especially if the site you built heavily rely on the theme. To do so, just paste the code below into the functions.php file of the theme. Once done, the client will not be able to switch themes anymore.

add_action(‘admin_init’, ‘cwc_lock_theme’);
function cwc_lock_theme() {
        global $submenu, $userdata;
        get_currentuserinfo();
        if ($userdata->ID != 1) {
                unset($submenu[‘themes.php’][5]);
                unset($submenu[‘themes.php’][15]);
        }
}

Source: Sltaylor.co.uk

Disable RSS feed

By default, WordPress include the popular RSS functionnality, which is great for blogs. But if you’re using your WordPress install as a static site, having RSS feeds may become a bit confusing for your visitors. This code will totally disable RSS feeds (As well as other formats) from your blog. Just paste the code into “functions.php“, and you’re done.

function cwc_disable_feed() {
wp_die( __(‘No feed available,please visit our <a href="’. get_bloginfo(‘url’) .‘">homepage</a>!’) );
}
add_action(‘do_feed’, ‘cwc_disable_feed’, 1);
add_action(‘do_feed_rdf’, ‘cwc_disable_feed’, 1);
add_action(‘do_feed_rss’, ‘cwc_disable_feed’, 1);
add_action(‘do_feed_rss2′, ‘cwc_disable_feed’, 1);
add_action(‘do_feed_atom’, ‘cwc_disable_feed’, 1);

Source: Wpengineer

Remove the WordPress Admin bar

Introduced in WordPress 3.X, the new “Admin bar” is an useful feature, but if you don’t like it, you can easily remove it. Just paste the following snippet into your “functions.php” file.

add_filter(‘show_admin_bar’, ‘__return_false’);

Source: catswhocode.com

For cool code snippets visit the following site wpmu.org, it has upto 100 code snippets.

Say Sometihng:

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>