Adsense

Wordpress tutorial and hack

Easily replace WordPress editor font

Don’t like the default font used by WordPress editor? No problem, the following code will allow you to change it. Simply paste it to your theme functions.php file. You can define which font to use on line 5.
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 }
Source: http://devpress.com/blog/fixing-wordpress-3-2s-html-editor-font/

Quick and easy maintenance mode

Sometimes, you need to put your blog on hold while performing some maintenance. Many plugins are allowing you to do so, but here is a simpler solution: Just paste the following snippet into your functions.php file and save it. Your blog is now unavailable to anyone except administrators. Don’t forget to remove the code when you’re done with maintenance!
function cwc_maintenance_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('Maintenance, please come back soon.');
    }
}
add_action('get_header', 'cwc_maintenance_mode');
Source: http://skyje.com/2011/05/wordpress-code-snippets/

Simpler login url

Would you like to be able to use a simpler url like http://website.com/login to login to your WordPress dashboard? If yes, just read this recipe to learn how to implement it on your own blog.
Open your .htaccess file (located at the root of your WordPress install) and add the following code. Remember to backup your .htaccess file before editing it!
RewriteRule ^login$ http://yoursite.com/wp-login.php [NC,L]
Source: http://www.wprecipes.com/simpler-wordpress-login-url

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: http://sltaylor.co.uk/blog/disabling-wordpress-plugin-deactivation-theme-changing/

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: http://wpengineer.com/287/disable-wordpress-feed/

Filter custom post types by author in admin

Here is a function which adds a dropdown select control of users next to existing filters (by default, date). It also works in tandem with the built in author filtering which is available when you click on an author in on admin listing pages (by default on posts and pages).
As usual, the only thing you have to do to implement this code is to paste it into your functions.php file.
function cwc_restrict_manage_authors() {
        if (isset($_GET['post_type']) && post_type_exists($_GET['post_type']) && in_array(strtolower($_GET['post_type']), array('your_custom_post_types', 'here'))) {
                wp_dropdown_users(array(
                        'show_option_all'       => 'Show all Authors',
                        'show_option_none'      => false,
                        'name'                  => 'author',
                        'selected'              => !empty($_GET['author']) ? $_GET['author'] : 0,
                        'include_selected'      => false
                ));
        }
}
add_action('restrict_manage_posts', 'cwc_restrict_manage_authors');
Source: http://forrst.com/posts/WordPress_Custom_Post_Types_Filter_by_Author_in-s9p

Add post thumbnails to RSS feed

This very cool piece of code will get the post thumbnail and automatically add it to your RSS feeds. Paste the code into functions.php and save the file. Don’t forget that you need to use a theme that supports post thumbnails for this snippet to work.
function cwc_rss_post_thumbnail($content) {
    global $post;
    if(has_post_thumbnail($post->ID)) {
        $content = '<p>' . get_the_post_thumbnail($post->ID) .
        '</p>' . get_the_content();
    }

    return $content;
}
add_filter('the_excerpt_rss', 'cwc_rss_post_thumbnail');
add_filter('the_content_feed', 'cwc_rss_post_thumbnail');
Source: http://snipplr.com/view.php?codeview&id=56180

Remove 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: http://speckyboy.com/2011/03/01/how-to-remove-the-admin-bar-from-wordpress-3-1/

2 comments:

  1. Great wordpress tutorial. This can help wordpress developers who is starting the career.

    Wordpress Development Company

    ReplyDelete
  2. Good wordpress tutorial for learners. Excellent example with codes.

    Web Design Company

    ReplyDelete

comment here

newest questions on wordpress