Category Archives: Code Snippet

shortcode in widget

Snippet: Enable Shortcodes In Widgets and Post Titles

Shortcodes are one of the most popular feature of the WordPress. It allows you to trigger a function within the post contents. We posted number of shortcodes you can use. Couple of builtin shortcodes are [gallery] and [embed]. Unfortunately, shortcodes does not work in text widget where we often like to use them. To enable it, you just need to paste following snippet in your functions.php

alternative-post-coloring

Snippet: Add “alt” CSS Class to Alternative Posts

If you want to have different look and feel for post one after the another. This snippet will let do that quite easily. It will add “alt” class to alternative posts and you can then change, lets say, background color or border to make it different from the adjacent posts.

require-featured-image

Snippet: Require Post Thumbnail to be Uploaded Before Publishing

This short snippet requires authors and admins to set a post thumbnail before publishing any article. It will update the post and all of its contents but wont publish it until the thumbnail is set. For custom post types, you just need to change the “get_post_type” condition to your custom post type.

media-metabox-fi

Snippet: Media Metabox to add additional images to posts

This snippet adds a gallery metabox where admin can either upload images through WordPress Uploader or put in the image URL directly. This metabox is very useful for the custom post types for which you want to upload multiple images. Some good examples are, real estate properties, work portfolios and store products. All of these would have a featured image and some images to be displayed in a (for example) slider to explain it features and qualities.

TeleTech

CSS: Full Page (Screen) Background Image Slideshow: Made Easy

Full screen background image that span all over the browser window is getting much more popular now. It definitely catches visitor’s eye and boost the overall design of the website. It looks much more colourful and attractive. Few examples of some awesome looking websites are TeleTech, Vivo Group, Chicago L-Shirts and Fleming Steele. This snippet is not specific to WordPress except that it require jQuery and uses WordPress conventions. Please note that it does not require any jQuery plugin.

contact-form-7

Snippet: Phone and Fax Number Validation in Contact Form 7

Contact Form 7 is the most simple and straight forward form plugin for WordPress. It has been downloaded nearly 10 million times. It has everything to set up a simple contact form except one thing, that is, validation of a phone or fax number. This short snippet validates phone number by stripping of all non-numeric characters and checking if numeric string is of length 10 digits.

track-post-views

Snippet: Track Views of Posts, Pages or Custom Post Types without Plugin

This snippet automatically track views of posts, pages and custom post types. You can use get_post_views function having optional $post_id parameter to fetch the number of views of any post, page or custom post type. You can also add “Views” column in admin panel for each post type.