Category Archives: General

Remove WordPress version number from the head section and RSS feeds & also from version parameter in JS and CSS files

Remove WordPress version number from the head section and RSS feeds & also from version parameter in JS and CSS files


By default WordPress adds a Meta tag in the headers which displays the current using WordPress version number.

This version number is added just for tracking the site on WordPress, it is not required by your application, but this information can be very much useful to hacker to identify which version of WordPress you are using.

If you are not using latest WordPress version, the hackers can target the known vulnerabilities in that version to hack your site.
You can check all the Vulnerability in “Open Sourced Vulnerability Database” founded at


There are various ways that can be used to remove this information below is the best one.


Add these following codes to in your functions.php file of your theme according to your requirements.


/* Function to hide WordPress version number
*  from the head section and RSS feeds on your site.

function my_remove_version_info() {
return ”;
add_filter(‘the_generator’, ‘my_remove_version_info’);


Remove the “ver” parameter from all enqueued CSS and JS files in the page


/* remove wp version param from any enqueued scripts (css/js)*/
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, ‘ver=’ ) )
$src = remove_query_arg( ‘ver’, $src );
return $src;
add_filter( ‘style_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
add_filter( ‘script_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );


Remove only the “ver” parameters which have WordPress version number from all enqueued CSS and JS files in your page.


/* remove wp version param from any enqueued scripts (css/js)*/
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, ‘ver=’ . get_bloginfo( ‘version’ ) ) )
$src = remove_query_arg( ‘ver’, $src );
return $src;
add_filter( ‘style_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );
add_filter( ‘script_loader_src’, ‘vc_remove_wp_ver_css_js’, 9999 );


It is always recommended that you have the most updated version of WordPress.


30 Top PHP Tips and Tricks & Coding Tutorials

Tip #1

$todayTimestamp = time();
/* Don’t Use.*/
$nextDay = $todayTimestamp + 86400;

/* Do instead.*/
$nextDay = strtotime(‘+1 day’, $todayTimestamp);
The first one will not work exactly if you move into or out of daylight savings time.

An extra problem is that the second example is more readable, specially if you add like 2 weeks and 2 days (‘+2 weeks 2 days’)
Use date_default_timezone_set() function before, if you doing calculation to a specific region.



Tip #2

Don’t use regexp to filter/match an email or an URL.There are already built-in filters in PHP for that.

$email = filter_var(‘[email protected]’, FILTER_VALIDATE_EMAIL);
See documentation on filter_var()



Tip #3

echo gives you more than one string as parameter.

Using some parameters is going to more faster than blending some variables into a parameter.

$a = ‘Hello’;
$b = ‘Scriptarticle’;
echo ‘Say ‘ .$a. ‘ to ‘ .$b;

//Below will faster
echo ‘Say ‘, $a ,’ to ‘, $b;



Tip #4

Use isset() instead of strlen() function

$str = “434e5”;

if (!isset($str{5})) {
echo ‘String must be at least 5 chars<br />’;

if (strlen($str) < 5){
echo ‘String must be at least 5 chars’;
isset() needs little more time than strlen() because isset() is a language construct.

When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string is at least that many characters long. (Note that the first character is element 0, so $str[5] is the sixth character in $str)



Tip #5

Avoid the use of printf function

Unlike print and echo, printf() is a function with associated function execution overhead. More over printf() is designed to support various formatting schemes. To handle formatting printf() needs to scan the specified string for special formatting code that are to be replaced with variables.

echo ‘Result:’, $result;
// is better than
printf( “Result.%s”, $result );



Tip #6

Avoid large string concatenation

When do concatenation string, avoid uniting with large size string. It can obstruct code execution that can display faster.


//Large string concatenation
$title = ‘this is’;
$body  = ‘..a very large blog..’;
echo “Subject.$title\n\n$body”;

//Avoid large string concatenation
$title = ‘this is’;
$body  = ‘..a very large blog..’;
echo “Subject.$title\n\n”;
echo $body;




Tip #7

Use boolean data type

PHP is allowing writing Boolean data type with uppercase or lowercase.
But, writing with lowercase is faster than uppercase. When found a constant, PHP do lookup hash constant name.


if ($var = TRUE) {


//this is more faster
if ($var = true) {


Boolean value 1 and 0 are faster than true and false.



Tip #8

Avoid space in your code

The main purpose of code optimization is to get faster code execution, because PHP codes going to execute every time they are requested.

Avoid the use of many spaces ( ) is a good thing. Every space is 1 byte and every tab (\t) is 1 byte. When you’re using four spaces, you’ve been use 4 bytes. It will more effective if you’re using a tab (\t).



Tip #9

Print Output

PHP is giving some sting functions to printing output into browser and we are often using print() and echo() function.

Print() function behavior like the other function in common and having return value integer 1. Thus, print() can used as part of expression which more complex. Meanwhile, echo() is able to accept more than one parameters all at once, and does not having return value.

print() ‘string 1’;
echo ‘string 1’;
// using some parameters
echo ‘string 1’, “string 2”, ‘…’;
echo() function string will execution more faster than print(). This differentiate caused by will return status (integer) which expose what process has done or not.



Tip #10

File Access Optimization

When you need to include a file, recheck file content that will be use. If file not contains PHP codes, use readfile() function to increase performance.
Because files that including with readfile() does not parsing by PHP. It will be different with construction language include() and require(), and files will be evaluated before.

Other side is, readfile() increases attack risk. This risk will be happen when accessing file from URL.
Solution for the attack risk is by using File Handling.



Tip #11

Use ternary operators instead of if, else

Ternary operators can be very helpful and clean up the code, but don’t over complicate them otherwise your code might become inundated with large amounts of complex ridiculousness.

$name = (!empty($_GET[‘name’])? $_GET[‘name’] .’Scriptarticle’);



Tip #12

Class Auto loading

If you have a very large number of classes that could potentially use within one or many sections of your code, you could include all of them within a common header file, or only include the ones that you know that you’re going to use on that page. However, you then need to remember to include new classes whenever we want to use a different one etc.


Use PHP function spl_autoload_register() instead of that.
You can use the below function where you will need to pass the name of the class that you’re trying to load as the first parameter of the function. As of PHP 5.3.0 we are able to use anonymous functions, basically a function thas has no name.

spl_autoload_register(function ($class){
echo ‘We are loading class.’ . $class;
include_once(‘classes/’ . $class . ‘.inc.php’);
echo ‘Class loaded.’;


In PHP5, there ia a magic function called as __autoload() for fulfilling the same purpose.



Tip #13


Passing variables by reference is a way to pass variables into functions so that the function can alter the original variable without having to return anything or define it as global etc. A function parameter that is going to be passed in as a reference is proceeded by an ampersand (&). Let’s see the below example.


function lowercase(&$string){
$string = strtolower($string);

$name = ‘STEPHEN’;
echo $name; // returns stephen


There are so many advantages of using references, for example you don’t have to return anything from the function, nor do you have to look to define them as globally accessible.

References are very useful when you use them with arrays. Let’s say we have a function that sets the first item in any array to flower.


function flowerArray(&$array){
$array[0] = ‘flower’;
$nonflower = array(‘mahesh’, ‘nirmal’, ‘saurabh’);
print_r($nonflower); // This will now have changed ‘mahesh’ to ‘flower’



Tip #14
Single Quotes vs. Double Quotes

You may or may not think about this point in your PHP use but it is kind of a big deal. Using the right or wrong quotes can not only cause errors that might be hard to find but there can be a slight performance boost and can make your code much easier to read.

echo ‘hello scriptarticle’;
echo “hello scriptarticle”;

These will produce the exact same end result but do you know which one is technically better? The single quote. The single quote just puts exactly what is inside of it without processing while the double quote actually evaluates and processes. Let’s take an example.


$example = ‘hello scriptarticle’;

echo ‘$example’; // outcome will be $example

echo “$example”; // outcome will be hello scriptarticle

As you can see here the double quotes take the time to process what is inside so technically there will be a little more overhead.

Obviously on a small scale this means nothing but if you have a loop that iterates 1000 or more times you might start to see the benefits of single quotes in a performance sense.



Tip #15
PHP Short Tags

You know when you just want to pre populate a form or add one PHP variable into the middle of an HTML block. Which one is more readable and easy to use PHP open tags or short tags?

<?php echo $name; ?>
<?=$name ?>

Lower one will produce the exact same output as the first but much neater and with a little less code. It’s it?
NOTE: A short tag is something that can be disabled in the php.ini so it is not guaranteed to work but industry standard has short tags enabled.



Tip #16
Working with zero filled numbers in PHP

Padding Zero is very easy to do by using PHP build-in functions.

<?php echo $new_number = str_pad($num, 3, “0”, STR_PAD_LEFT); ?>

Remove padding zero
<?php echo intval($new_number); ?>



Tip #17
Know the Difference between Comparison Operators

$sentence = ‘scriptarticle is very good blog’;

if (strpos($sentence, ‘scriptarticle’)) {
echo ‘I like scriptarticle.’;
} else {
echo ‘I don\’t like scriptarticle..’;

Because the substring “scriptarticle” occurs at the very beginning of “scriptarticle is very good blog”, strpos() correctly returns 0, indicating the first position in the string. Because the conditional statement treats this as a Boolean, it evaluates to FALSE, and the condition fails. In other words, it looks like ‘scriptarticle’ is not in the sentence but it is!

This can be corrected with a strict comparison as below.

if (strpos($sentence, ‘scriptarticle’) !== FALSE) {
echo ‘I like scriptarticle.’;
} else {
echo ‘I don\’t like scriptarticle..’;




Tip #18
Methods in derived classes run faster than ones defined in the base class.



Tip #19
Accessing arrays
e.g. $row[‘id’] is 7 times faster than $row[id]



Tip #20
Avoid functions inside loops

Try to use functions outside loops. Otherwise the function may get called each time and obeviously it will affect performance.

/*  loop with a count() inside the control block will be
executed on EVERY loop iteration.
$max = count( $array );
for( $i = 0; $i < $max; $i++ )
// do something here

// is better than
for( $i = 0; $i < count( $array ); $i++ )
// do something here

It’s even faster if you eliminate the call to count() AND the explicit use of the counter by using a foreach loop in place of the for loop.

foreach ($array as $i) {
// do something



Tip #21

When you need to output a large or even a medium sized static bit of text it is faster and simpler to put it outside the PHP.

This will make the PHP parser effectively skip over this bit of text and output it as is without any overhead. You should be careful however and not use this for many small strings in between PHP code as multiple context switches between PHP and plain text will be away at the performance gained by not having PHP print the text via one of its functions or constructs.



Tip #22
true is faster than TRUE

This is because when looking for constants PHP does a hash lookup for name as is & since names are always stored lowercased, by using them you avoid 2 hash lookups. Furthermore, by using 1 and 0 instead of TRUE and FALSE, can be considerably faster.



Tip #23
Incrementing or decrementing the value of the variable

When incrementing or decrementing the value of the variable $i++ happens to be a slower then ++$i.++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zends PHP optimizer.

It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.


* Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
* Incrementing a global variable is 2 times slower than a local variable.
* Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
* Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.



Tip #24
Free unnecessary memory

Unset your variables to free memory, especially large arrays.



Tip #25
Specify full paths

Use full paths in includes and requires, less time spent on resolving the OS paths.

include( ‘/var/www/html/your_app/database.php’ );
//is better than
include( ‘database.php’ );



Tip #26
Use get_browser() built-in function to get browser information

Easily get your hands on the user’s browser-type.Some programmers leave this process to the browser end but can be useful to get this info server side.



Tip #27

This print a debug-style list of what was called to get the point where this function is called.



Tip #28
Automatic optimization for your database

You will probably add and delete tables from time to time. Therefore, you should use a solution that works no matter how your database looks like. For this, you can use this PHP script that finds all your tables, and then perform Optimize on every single one.

$tables = mysql_query(“SHOW TABLES”);

while ($table = mysql_fetch_assoc($tables))
foreach ($table as $db => $tablename)
mysql_query(“OPTIMIZE TABLE ‘”.$tablename.”‘”)
or die(mysql_error());


Tip #29
require() vs. require_once()

Use require() instead of require_once() where possible.



Tip #30
Secure HTTP connections

You can force a secure HTTP connection using the following code,

if (!($HTTPS == “on”)) {
header (“Location.https://$SERVER_NAME$php_SELF”);



Customize JQuery UI datepicker with From and To date

I think you have used the JQuery UI datepicker many times and you have also faced trouble when there are 2 date text-boxes and you have to use datepicker in both with taking care that one text-box date value always less than the 2nd one.


I think you have got my point, what I want to say.
Like you have two date fields named as FROM and TO and FROM date should always less then TO date.


For solving the same you have to make a trick in the datepicker function.
Below is the same you can use.


Just add below three lines to include CSS and JS  in your document head as below.


Head Section:

[sourcecode language=”plain”]

<link rel="stylesheet" href="" type="text/css" media="all" />

<script type="text/javascript" src=""></script>

<script type="text/javascript" src=""></script>



JavaScript Code:

[code lang=”js”]
<script type="text/javascript">


dateFormat : ‘dd/mm/yy’,
minDate : new Date(),
maxDate : ‘+1Y’,
defaultDate: "+1w",
changeMonth: true,
onSelect : function(selected){

var arr = selected.split("/");
var spares = [arr[2], arr[1],parseInt(parseInt(arr[0])+1)];
var joint = spares.join("/");
var minDate2 = new Date(joint);
$("#datepicker2").datepicker("option","minDate", minDate2);




dateFormat : ‘dd/mm/yy’,
minDate : "+1",
defaultDate: "+1w",
maxDate : ‘+1Y’,
changeMonth: true,
onSelect : function(selected) {

$( "#datepicker" ).datepicker( "option", "maxDate", selected );





HTML Code:

[sourcecode language=”plain”]
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<td colspan="2">From Date:</td>
<td><input type="text" value="" name="indate" id="datepicker" /></td>
<td colspan="2">To Date:</td>
<td><input type="text" value="" name="outdate" id="datepicker2" /></td>


For further reference you can go through the JQuery UI library by the below URL.

JQuery UI datepicker


I hope this all will help you.

Let me know by comments, if you still face any issue related to above.


Some Essentials WordPress Plugin every WordPress site owner should install

Some Essentials WordPress Plugin every WordPress site owner should install.


Better optimized theme

You should choose the theme as per your website is made for. If your website is a shopping cart then it should be attractive.
If it is just for blogging then it should be very simple and easy to load, so whenever the website owner starts with WordPress, he should choose the theme very carefully and according to your website needs.


There are many WordPress theme available for Free and Paid.


301 Redirect

In WordPress permalinks, for make your site better in search engine you have to select the proper permalinks for URL.
Suppose you have selected a structure (permalink) for URL, and after sometime you found it not appropriate for your site and SEO.
Or you have found that the POST or PAGE title is not as good for SEO and therefore you need to update that, then it will create a problem for Search Engine Webmaster Tools.


The problem is that the URL (old one) is already crawled by Search engines and it will take time to crawl the website again by the search engine.
During this period, if users come to your site using search engine and click on that URL then it will redirect the user to 404 page of your website.
I think no webmaster like this.


So for that we have a solution called as 301 redirect(permanent) redirect of the old url to new url, we can do the same using .htaccess Tricks.
For making or easing the same we have a very simple plugin called as 301 redirect, according to me every website owner who use WordPress should install this, this will automatically do this job for you.


WordPress SEO plugin by Yoast

SEO is a very vast field in web technology, the main concern of SEO is to make the site optimized and popular so that search engines will prioritize your website URL to display it first.


Yoast always proved his superiority in SEO, and they have developed a very good and nice SEO plugin for WordPress, it helps the website owner a lot to optimize and increase the traffic on the site.


W3 Total Cache

If your website have a lot of images or content and js and css files, then it will slow down your website to load on browser, i.e. your page speed will slow down. There are lot of technique that can be used as the js and css minified. Cache the content and images, so that it will help the browser to load the page speedily.

The ‘W3 Total Cache’ plugin will help you to speed up the pages loading time.


Captcha and Contact Form 7

As if your website will popular and people will want to contact with you, for that you need some type of form for contacting?
Contact Form 7 is very easy to use and customizable according to your theme.


Share Buttons for Twitter, Facebook, Google+ & more

In today’s world we know how much people and how many times they use social networking website, so to make your website popular, you should add social networking links. That can be used by the user to share the articles. It will help to make your website popular as almost all the guys use internet have some social website account.


If you like this article, I have also given the links for sharing this, so click on those to share this with your friends.
Below WordPress plugin is there to fulfilling the same job in very easy manner.


Facebook fan Page

Facebook fan page increase your website subscribers.
and your website popularity and traffic will increase rapidly.

You can use the below WordPress plugin for the same, it will prove very helpful.



Google Custom Search

Google custom search improve the search functionality in your website as you all know how powerful Google is.
So if you add Google custom search in your website then it will handle the search functionality of your site very easily and very fast i.e. the result will display very fast.


It fetches the result from its database i.e. it show the related indexed pages from Google database of your website.
However it is very easy to integrate, but it is more simpler by using the WordPress plugin , if you are using WordPress.
Use the below WordPress plugin, to add Google custom search in your website.




A dynamic website is totally depends on its database. Optimized databases always help in speeding up the page load time and optimize the site.
The Database of your website should be safe, so for that you should take backup of your database at a regular interval, so if your website faced some malicious threat attach then you can recover by the backups files and database.

The below WP-DBManager WordPress plugin have almost all the functionality related to the database.
According to me every webmaster should install this plugin to optimize the database and backups.



Feedburner Email Subscription

Email subscription is the way by which the user can register for your website and will get all the update related to new post added, update or deleted.

Google Feedburner Tool helps a lot in this and provides a very good functionality related to this.
For implement this Google Feedburner helps and guides to integrate this in your website.
If you are using WordPress then you can use the Feedburner Email Subscription plugin and can enjoy the great functionality it have.
I have also integrated this in my website, If you want to subscribe for my website updates Go to left sidebar and enter your email in the box and submit.



Better WP Security

WordPress Open source CMS is used by very large number of users, so the way of coding in WordPress and functions URL can be easily known to the hackers.
So you should aware, if you are using WordPress in your website.
Like wordpress admin access URL is usually wp-admin.


Mostly the admin user id is 1 and username is admin, username can also be known easily using the login form submission using wrong password.
Generally the table prefix is wp_.
.htacces, wp-config (file where the main site configurations present) read/write permission and so on.


To protect your website from these all, you should install Better WP Security plugin in your WordPress site admin.
Please take care before installation as it takes effect and update core and server configuration files.
So take backups of files and database before installation and activation of plugin.
If have just installed WordPress then you can install and make active without any head-ache but if your website is in running stage and you have lot of content then you should take care in each and every step of activation, every single step can make your website in unstable state, so be careful.



These WordPress plugins are essentials, i.e. every master should install these in his website.


These will help to make popular your website, increase the web traffic and optimize your website.
Let me know if you face any issue related to above WordPress Plugin.



What is the difference between GROUP BY and ORDER BY in MySql?

What is the difference between GROUP BY and ORDER BY in MySql?


Mostly this question has been asked by the interviewer, even if you have used it many times but at that time generally the guy not satisfied the interviewer by the answer.


Please go through the below and give very appropriate answer and increase your chances of selection.




GROUP BY is used to make the group-set of records based on the fields of the table or you can say GROUP BY keeps related data items together.


GROUP BY clause often used with the aggregate functions (SUM, AVG, MAX) on the columns in a query the other columns should be in group by query, you can use HAVING clause to apply the condition on the group-set that will fetch by the query.


Let’s take an example:
Suppose we have a table student as below.



Id                     Name
01                     Nirmal
98                     Stephen
65                     Mahesh
65                     Hodge
90                     Pamlea
90                     Paul
90                     Shakira


Question 1: Due to some mistake by the programmer, there was some duplicate id for some students. Fetch which id is duplicated and how many times?


[sourcecode language=”plain”]
SELECT Id, count(Id)
FROM tbl_student


Question 2: Fetch which id is duplicated and how many times and the Ids should be greater than 80.

[sourcecode language=”plain”]
SELECT Id, count(Id)
FROM tbl_student
HAVING Id > 80




The ORDER BY clause is used to sort the result-set by a specified column either by ASC or DESC.
By default, ORDER BY clause sorts the records in ascending order.


ASC = Ascending (shortest first)
Desc = Descending (largest first)


[sourcecode language=”plain”]
FROM tbl_student


I think it will make sense?


AJAX Loading Icon Generators Tools

In the field of web development, generally you need to show indicator image until the code/response will ready to display.


You can also call the indicator image as an “AJAX loading” icon or a “preloader image”. It is commonly used on AJAX-base sites and applications, informing the user that the site is still processing the request and fetching some data.


You all know how important the UI is, so you always want the very good indicator image, If I am not wrong designer is not always ready to do these type of small stuff for you 🙂


No worries, we have very good live solutions for that and it is totally free and customizable to fulfilling your need.


AJAX preloader images/gifs

Create your AJAX preloader images online dynamically without any head-ache


The main customizations you can do are

1) Select the AJAX image indicator according to your wish
2) Set background image color or can make transparent
3) Set foreground color
4) Set size of the indicator GIF
5) Update animation speed
6) Size of the image and many more


AJAX Loading Icon Generators Tools