Remove theme editor from WordPress setting menu

Many wordpress developers want to remove the theme editor option from wordpress appearance settings menu. Due to security reason removing theme editor from wordpress admin section is really great idea.

In this tutorial I given simple steps to remove theme editor option from your wordpress admin section.

You just need to copy and paste following code into your functions.php file. That will hide the theme editor menu from settings page.
Using following code you can easily remove editor.

function wpapi_remove_editor_menu() {
  remove_action('admin_menu', '_add_themes_utility_last', 101);
}

global $remove_submenu_page, $current_user;
get_currentuserinfo();
if($current_user->user_login == 'admin') { //Specify admin name here
    add_action('admin_menu', 'wpapi_remove_editor_menu', 1);
} 
Remove theme editor from WordPress setting menu
Remove theme editor from WordPress setting menu

How to make empty wordpress trash automatically

Sometimes we create pages and posts which are unwanted. In this article, I given code for make empty wordpress trash automatically. Using code deleted items will automatically delete from trash. Open your wp-config.php file which is in the root directory of wordpress installation.

How to make empty wordpress trash automatically

How to make empty wordpress trash automatically
How to make empty wordpress trash automatically
define('EMPTY_TRASH_DAYS', 7 );

Above code will delete the comments from trash section after every seven days.

Seven days are safe to keep trash. This is simple but good option to keep in your wordpress blog.

Display the authors in dropdown menu using wp_dropdown_users – Hook/Filter

One of my client faced issue with Autor drop down which is in Admin section.

Display the authors in dropdown menu using hooks.

While creating the New post there was problem with the Author field. There are hundreds of irrelevant selections (users) and it’s difficult to select the right one.

WordPress is by default showing all the users in author drop down. I don’t want to show the other users in author drop down.

Display the authors in a dropdown menu
Hook/Filter – In wordpress Admin -Add new Post section -Display the authors in a dropdown menu using wp_dropdown_users One of my client faced issue with Autor drop down which is in Admin section. Display the authors in a dropdown menu using hooks

I searched for wp_dropdown_users hook or filter. But I did not found any proper solution.

Following articles are found helpful to me.
http://wordpress.org/support/topic/filter-for-post-quick-edit-author-drop-down
http://codex.wordpress.org/Function_Reference/wp_dropdown_users

Using that code I modified the code and I am able to fix the issue. You can put following code in to functions.php file.

 /*
 * Hook for showing Admin and Author in Add new Post - Admin section dropdown menu
 */
function wpapi_override_wp_dropdown_users($output) {
    global $post, $user_ID;
    //get the Admin-role users IDs
    $admins = getUsersWithRole('admin');
    //get the author-role users IDs
    $authors = getUsersWithRole('author');
    //merge the array
    $result = array_merge($admins, $authors);

    //array converted into comma seprated string
    $authorsall = implode(",", $result);

    // return if this isn't the theme author override dropdown
    if (!preg_match('/post_author_override/', $output))
        return $output;

    // return if we've already replaced the list (end recursion)
    if (preg_match('/post_author_override_replaced/', $output))
        return $output;

    // replacement call to wp_dropdown_users
    $output = wp_dropdown_users(array(
        'echo' => 0,
        'name' => 'post_author_override_replaced',
        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
        'include_selected' => true,
        'include' => $authorsall
    ));

    // put the original name back
    $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);

    return $output;
}

add_filter('wp_dropdown_users', 'wpapi_override_wp_dropdown_users');

/*
 * Find User IDs by Role
 */

function getUsersWithRole($role) {
    $wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
    return $wp_user_search->get_results();
}

Using above code, you can load multiple role users in author drop down.

Using social button will slow down your wordpress site

WordPress Tips, Using social button will slow down your wordpress site. There are so many social button plugins. Which are so beautiful and nice plugins.

Using social button will slow down your wordpress site

But these plugin can cause wild swings in page load times and page load.  Sometimes, facebook is busy and that icon slows down your page, sometimes it is twitter.
Some time admin selected so many social icons to show and it takes time to load because that many apache requests will go to server. I personally tested some blogs and They are facing same page load issue. Commonly wordpress page will load in 5 to 6 seconds without this wordpess plugin. But with these plugin it is taking 50 to 60 seconds to load the page.
It will affect to SEO of your site.

Our Test

We tested the following social icons buttons.
Twitter, Twitter (tweet), Facebook, Facebook (like), Delicious, Google Bookmarks, Google Reader, Google email, Posterous, and StumbleUpon.
All icons are failing some time and that causes page load error with your wordpress site. I tested other plugins also which are not for social sharing purpose but there were no issue with worpdress page loading.
commonly these type of plugin will load into your post, page and excerpt. If you open home page or archive page. you will face the slowness.
I am not saying not to use the social share or social button plugin in your wordpress site. But you need to think about wordpress plugins which is causing issue to your site.
Using social button will slow down your wordpress site
Using social button will slow down your wordpress site
I recommond following wordpress plugins which are really nice.

rtSocial

Normally social sharing codes provided by facebook, twitter, etc renders iframes at run-time. These iframes increases page-size and slow-down your website (on client-side).

Flare

Up your website’s social score with a little social Flare! Easily configure and share your blog posts across some of the most popular networks.

Lazy Social Buttons

Social buttons attract more visitors to your site. When users +1, Tweet, or Like your page, it advertises your page to their friends and followers. This plugin adds social buttons to your posts as a small sprite at first and delays loading the real buttons until the user hovers over the social buttons. It delays ~300KB of social button components by loading <6.5KB of our own script and sprite. onMouseOver activates the load of the ~300KB of social button components.

WPSocialite

No one likes long load times, but we all want to be able to share our content via Facebook, Twitter, and other social networks. These take a long time to load. Paradox? Not anymore! With WPSocialite (utilizing David Bushell’s amazing SocialiteJS plugin [http://www.socialitejs.com/]) we can manage the loading process of our social sharing links. Load them on hover, on page scroll, and more!

Best one

CSS Share Buttons

fast loading share button wordpress plugin
fast loading share button wordpress plugin

Facebook, Twitter, Google Plus and LinkedIn Share buttons. Super Fast Loading, No Javascript, Only CSS. Responsive Design, Floting Sidebar Option.

The CSS Share Buttons easily allows your blog to be shared. Speedup you site with this share plugin.

Super Fast

This plugin is very light weight. As compared to other Share button plugin This plugin is super fast.

We compared with all famous share button plugin. Our Plugin load CSS from CDN.

It show very lite share button only with HTML and CSS. It does not load any javascript like other We load only one CSS file with this plugin – only 1.5kb css file.

how to disable cron job in wordpress

Before every post visit wordpress cron is running and taking too much bandwidth.  So we given trick and code to disable cron job in wordpress, which will disable wordpress cronjob.  if you have a lot of visitors it can be a problem. I am convinced this is the reason why my admin has become glacially slow and my site often crashes when making edits.

how to disable cron job in wordpress

Disable the wp-cron.php

you need to add the code to your wp-config.php file.


define('DISABLE_WP_CRON', 'true');

If you have shared hosting then add the following cron job


php -q wp-cron.php

If you have your own server then you need to add the cronjob in crontab


* */1 * * *wget https://purabtech.in/wp-cron.php

how to disable cron job in wordpress
how to disable cron job in wordpress

use animated smileys and emoticons in wordpress post

Smiles and emoticons are always important show your expressions in short way. Earlier also I posted articles about same. Here is link about that. here in this article written about animated smileys. I given very detailed information to use animated smileys and emoticons in wordpress. animated smilyes and emotions are used everywhere now in mobile device.

use animated smileys and emoticons in wordpress

By default wordpress supports some basic emoticons. Here I can suggest some very cool wordpress plugins.

Kaskus Emoticons

Kaskus Emoticons is an emoticon set inspired by Kaskus, the Largest Indonesian Community – consisting of over a million active members from all over the world. The images which are used in this plugin are copyright of Kaskus

Speedy Smilies

Speedy Smilies takes emoticons in WordPress to the next level (where it should be already and hopefully one day will). The end goal is to make smilies load faster in the browser for visitors and make them easy to insert into posts/pages for authors. In addition to the speed benefits, Speedy Smilies allows authors to easily change the appearance of emoticons using smiley sets.

Speedy Smilies is free software licensed under the GNU GPL version 3.

Tango Smileys Extended

Tango Smileys Extended (TSE) disables the built-in WordPress smileys and extends the number of available smileys from 18 to 202. The extended smileys can be input using standard emoticon shorthand, or through the CTI (Click to Insert) interface. Smileys in comments is supported and may be inserted using the standard emoticon shorthand or through the CTI interface. MCEComments is also supported.

This version of Tango Smileys Extended is for WordPress 2.8+
WordPress versions pre-2.8 are no longer supported. If you are using WordPress 2.7.x, please use Tango Smileys Extended 2.5.4.1. WordPress 2.6.x and earlier are only supported in versions of Tango Smileys Extended older than, and including, 2.5.2.8.

Moods Addon for Ultimate TinyMCE

This plugin is designed to be used as an add-on to my Ultimate TinyMCE plugin. However, it can also be used as a stand-alone plugin as well.

For best results; You can download Ultimate TinyMCE here:
http://wordpress.org/extend/plugins/ultimate-tinymce/

This addon will add a button to your visual tinymce editor for posts/pages. Clicking the button will open a popup window with over 50 professionally animated .gif smiley’s.

You can insert these smiley’s into your post/page content areas. Simply click a smiley, and it is automatically inserted into your content area.

Font Emoticons

Replaces WordPress’ smileys (based on images) with font-based emoticons (see screenshots). Font-based emoticons have some advantages:

  • They have the same size as the surrounding text. No more distorting the heights of lines containing smileys/emoticons. They always fit the font size.
  • They have the same color as the surrounding text.

The following emoticons are supported:

  • :) :-) :smile:
  • :( :-( :sad:
  • ;) ;-) :wink:
  • :P :-P :razz:
  • -.- -_- :sleep:
  • :thumbs: :thumbsup:
  • :devil: :twisted:
  • :o :-o :eek:
  • 8O 8o 8-O 8-o :shock: (No real icon for “shock” yet. Using “eek” instead.)
  • :coffee:
  • 8) 8-) B) B-) :cool:
  • :/ :-/
  • :beer:
  • :D :-D :grin:
  • x( x-( X( X-( :angry:
  • :x :-x :mad: (No real icon from “mad” yet. Using “angry” instead.)
  • O:) 0:) o:) O:-) 0:-) o:-) :saint:
  • :'( :'-( :cry:
  • :shoot:
  • ^^ ^_^ :lol:

Notes: * Emoticons must be surrounded with spaces (or other white space characters); e.g. the emoticon in that:)smile won’t be replaced * Emoticons won’t be replaced in HTML tags nor in <pre> or <code> blocks.

wp-Monalisa

wp-monalisa is the plugin that smiles at you like monalisa does. place the smilies of your choice in posts, pages or comments.

There are a lot plugins for smiley support out there and some of them are really useful. Most of them don’t work out of the box and this is what wp-monalisa tries to achieve, giving you the ability to maintain your smilies and even turn them into img tags.

it’s easy and it smiles at you…what else do you want?

Features:

  • maintain your smilies in a separate directory
  • activate or deactivate smilies for posts or comments
  • replace smilies with img tags
  • extend or replace wordpress smiley replacement
  • while edit posts or pages, pops-up in a draggable meta-box
  • extends your comment form to give you visitors the freedom to smile 🙂
  • support for fckeditor (tested with v3.3.1)
  • fully integrated ith BuddyPress
use animated smileys and emoticons in wordpress post
use animated smileys and emoticons in wordpress post

get posts vs new wp_query in wordpress theme

For getting the wordpress posts we use the following methods. In every wordpress theme we always use the get_posts() vs WP_Query vs query_posts() methods for creating the wordpress theme. We should know about wordpress methods first.

get posts vs new wp_query in wordpress theme

 

  • query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like making use ofpre_get_posts hook, for this purpose. TL;DRdon’t use query_posts() ever;
  • get_posts() is very similar in usage and accepts same arguments (with some nuances, like different defaults), but returns array of posts, doesn’t modify global variables and is safe to use anywhere;
  • WP_Query class powers both behind the scenes, but you can also create and work with own object of it. Bit more complex, fewer restrictions, also safe to use anywhere.

As per my opinion you should use the WP_Query() method. This is secure to use. If you have a choice, go with WP_Query. Both of the other functions (query_posts() andget_posts()) call WP_Query indirectly.

get posts vs new wp_query in wordpress theme
get posts vs new wp_query in wordpress theme

How can we save Ram usages using some wordpress theme tricks

While running wordpress site, save Ram usage is always great idea and you can easily improve the site performance by simple wordpress theme tricks.

We mostly use the get_permalink(), get_the_title() methods in our wordpress theme. Do not pass the post ID as parameter.

if you’re doing a get_permalink or get_title() call with Post id, 8 out of 10 times you’ll need to more of that post than just the permalink, so this isn’t really a problem.

save Ram usage

Post object is actually already slightly faster than calling get_permalink with $post->ID (in get_post it then only sanitizes and adds to cache, it doesn’t fetch new data), but the real benefit comes when you add a variable called filter in the $post object, setting it to “sample”. Now you decide whether that post object is going to be cached or not and which variables it contains.

Pass the $Post object instead of Post ID.

Do not use the Custom fields. Your server need to fire extra custom quries on Mysql server.

If your are using $wpdb->get_results or new WP_Query( $args ) then add the order by.

How can we save Ram usages using some wordpress theme tricks
How can we save Ram usages using some wordpress theme tricks

If wordpress site is hacked then how to fix issue

Recently one of my wordpress site is hacked which is on wordpress. There is something wrong happening on server. We fixed issue with some steps, we given full steps for fixing issue. Due to disk I/O notification and CPU usages notification email I got to know.

If wordpress site is hacked then how to fix issue

There is something wrong happening on server.

First thing I did which is checking the apache access logs and error logs. I was getting per second 100 request from some IP addresses.

I stoped apache server and I took my database and filesystem backup. Deleted my admin username and added new administrator with new username.

You should use the Better WP Security wordpress plugin. This is very useful plugin.

iThemes Security (formerly Better WP Security)

I added following code in my .htaccess file

 # BLOCK BAD IPS
 <limit GET POST PUT>
 Order Allow,Deny
 Allow from all
 # uncomment/edit/repeat next line to block IPs
 # Deny from 123.456.789
 Deny from 192.111.152.122
 Deny from 192.111.144.233
 Deny from 110.85.90.123
 </limit>

If wordpress site is hacked then how to fix issue
If wordpress site is hacked then how to fix issue

But above code was still not helpful to me because disk I/O and apache process was taking time to sending the request to 403.

Then I blocked the IP Address on My Linux server using following commands.

 iptables -A INPUT -s 192.111.144.789 -j DROP
 iptables -A INPUT -s 192.111.152.122 -j DROP
 iptables -A INPUT -s 192.119.144.123 -j DROP

This solved my issue.

wordpress get post meta custom post type: Smart way

WordPress tutorial for, wordpress get post meta custom post type smartly. The get_post_meta method is very useful in wordpress. here is simple code snippet.

wordpress get post meta custom post type

If you want to shorthand the get_post_meta call for the current post then you can use following:
you can use above method through functions.php file. You need to put following code in file:

function get_current_post_meta($key,$postID=null){
if(empty($postID)) {
global $post;
return get_post_meta($post->ID,$key,true);
} else {
return get_post_meta($postID,$key,true);
}
}

and you can call it like this:

echo get_current_post_meta('custom_tags');

Using above method you can pass the post id also.

wordpress get post meta custom post type: Smart way
wordpress get post meta custom post type: Smart way