Latest Snippets

Snippet: Get Random Post Link

Code snippets to fetch link of a random post of your blog.

color pallete

Snippet: Add Custom Colors in Editor’s Color Picker

This short snippet will add three colors (#15375c, #3366FF and #9fb83f) to color picker of WordPress editor. Its pretty useful if you allow administrators and authors to select the common colors of your website.

sorting

Snippet: Numeric sortable column for custom post type in admin panel

Many developer used Property, Car, Product and several others as a custom post type which, by default, sorted by publishing date (very odd). This fairly simple snippet details how one can add a sortable numeric column (for example a pricing column) in listing view of custom post type. It is quite useful as custom post types are getting popular day by day.

content-tree

Snippet: True in_category Conditional function

This is an advanced version of default in_category function. This function not only check for existance of post in the specified categories but also in all the subcategories down in the tree. It has same in_category parameters So you can use it in replacement of in_category.

view_sidetree

Snippet: Configure Child Categories to use their Parent Category Template

WordPress categories follow a predefined template hierarchy. In most cases, we use “category-$slug.php” to override the template for an individual category to give it a entirely different look and functionality (“category-projects.php” for a “Project” category). If you have subcategories (Design, Development etc) of “Project” they also follow the WordPress template hierarchy and you have to create “category-design.php” and “category-development.php” to give them the similar look as of Projects category. This snippet allow you to configure some or all child categories to use their parent’s category template. In the scenario we just mentioned above, Design and Development categories will also land at “category-projects.php” instead of their own “category-$slug.php” template.

plugin links

Snippet: Additional Links in Plugin Dashboard

Following snippet is specifically for WordPress Plugin developers. It lets the developer add additional links below their plugin descriptions and beside the “Activate” or “Deactivate” links. This is very handy to provide quick links related to your plugin or author.

1362414119_Document-scheduled-tasks-icon

Snippet: Set up a Cron Job in WordPress

You are normally using your server’s Crontab to schedule your cron jobs. If you do not have access to server panel or you do not understand its functionality correctly, you can use WordPress’s job scheduling to execute your crons. You can set up cron for hourly execution, daily execution and executing twice in a day. Here is how you can set up hourly and daily jobs.