Check where function is defined

To find out where the function is being defined, you can use the ReflectionFunction object.

The ReflectionFunction class reports information about a function.

Cannot display special characters

We have to work with various types of data everyday. We save data, retrieve them, modify them.

Sometimes, we have to work with special characters like below.

And when we try to print these special characters, all we get is

Now, this is not what we want to be displaying in the screen.

This is most probably because of the “mysql_set_charset“. We have to manually change the character set. We can do this when we select the database.

Add Conditional Styles in WordPress theme

A Standard Conditional IE comment looks like this

You can easily code this in your header.php file and it will work fine but it’s not a good practice to do so. A better option is to use the functions and hooks provided by WordPress. You can add the following code to your functions.php file

Pagination – Same list of posts in every page issue !

As per Wikipedia, Pagination is the sequence of numbers assigned to pages in a book or periodical.

In WordPress, we generally use WP_Query or query_posts to fetch posts and display the list with pagination. A simple query would look like this:

This will work just fine in most of the cases but sometimes we hear issues that the pagination is not working properly or pagination numbers are correct but every page shows the same list. It’s mostly because we haven’t included the ‘paged‘ parameter to the query. The following is taken from WordPress Codex.

you add the parameter like this:

The next example is exactly the same as above but with the parameters in an array:

Detailed information about how to properly configure and work with WordPress Pagination can be found in the WordPress Codex.

Shortcode, Beware of them

shortcodeSince the the release of WordPress 2.5 Shortcodes have been really popular and developers and user love it. Shortcodes have been extensively used to create a visually good looking content in WordPress.

Basically Shortcodes converts multiple lines of codes that performs specific task to a small WordPress specific code. Shortcodes looks like this [shortcode] or if wrapped with contents may look like [shortcode] Some Content Here [/shortcode].

Shortcodes have been used for multiple purposes like

  • displaying recent posts
  • Creating multiple columns
  • Create a  blockquote
  • Create tabs and accordions
  • Simple Tabs
  • Display Twitter Feed, Etc and many more.

So why this article? Is Shortcode Bad?

No, Shortcodes are really useful and it has brought many easy solutions for developers and users. But, if shortcodes are setup directly in theme, then it might create problem in future. This is because when we implement shortcodes in a theme directly, it becomes available to that particular theme only. If we change to another theme then all of the shortcodes will be unavailable and all we will be left is texts and visually it will look really bad. All the styles that came with shortcodes will be gone, if you had setup tabs and accordions will be gone. if you were displaying recent posts, you will only get something like this [recent-posts].

When creating shortcodes we should keep in mind all the factors that might affect the site if we use the shortcode. The best solution of this would be creating a separate plugin for the shortcodes with all the necessary styles and functions. This will make the shortcode independent of the theme and easily be run and implemented without hampering the site’s look even if the theme is changed.

Some good available plugins for Shortcodes are:

But in the end it’s up to you to decide how to use the shorcodes in the best way possible. Happy Coding 🙂

Custom PHP file in WordPress Theme

WordPress has proved to be one of the best platform for Developers and it provides a complete package for building a full Website. But sometimes we developers may need to add one or more custom PHP pages for various reasons.

Suppose you have a template file for your contact page and you built a custom form which when submitted will direct to send-contact-mail.php file and then that file will be used for form data manipulation and send mail. Here, you can easily use the php mail() function easily and achieve your goal but what if you want to use the WordPress actions in the file?

By default, your send-contact-mail.php is not recognized by WordPress and you cannot use any of the WordPress functions like get_bloginfo(‘url’); or in our case wp_mail(); function.

So What Do We Do?

The solution is quite easy. All we need is to include the wp-load.php file in our custom php page. The wp-load.php is location in the root of the site and it will make your custom php file compatible with WordPress functions.

However, there are many critics on including wp-load.php file. When you don’t know where the wp-load.php file is, it creates problem when including the file.

For more detailed information you can visit