wordpress logo

Loading all WordPress posts having or not having a custom meta field

wordpress logo

In a scenario one would like to create a custom meta key value pair for a post and save some value into it. Assume of an existing blog with hundred of posts which you want to add a custom field. Also assume a case in which you can only edit one post at a time and enter custom meta key value one by one. Continue reading

wordpress logo

Controlling rel canonical tag in WordPress

wordpress logo

I used a forum plugin in wordpress. This plugin provides a shortcode which is placed on a page. Once place this single page is used to shows forum home page, forum category pages and topics pages as well. For the sake of SEO i didn’t want the canonical tag e.g. <link rel=”canonical” href=”http://my-website.com/section” /> to appear of forum home page and subsequent pages. Continue reading

A simple way to debug a php application in production mode

How to get file extension using PHP

A simple way to debug a php application in production mode

A simple yet powerful approach to get file extension using PHP. We usually need to extract file extension from file name while uploading file so that we could generate new name and rename file to our convenience. We could create new file name using time, random or hashing, example of which has been given at the last paragraph of this post.

function get_file_extension($filename) {
    return substr($filename, strrpos($filename, '.')+1, strlen($filename)-strrpos('.', $filename));
}

Explanation:

It uses built-in substring, strrpos and strlen functions to extract file extension. A brief on these functions. Continue reading

wordpress logo

WordPress + Web.config “not found” error on home page

wordpress logo

I was trying to setup wordpress on IIS when i faced this problem. I placed a web.config file with given xml code and pretty urls (permalinks) worked fine on all page except the home page. Home page gave a Not Found error while pretty permalinks worked find on all other pages. After adding the following code (given below) in system.webServer settings to web.config it worked find. In short the code given below adds index.php as a default document root. Continue reading