Snippets

a minute read
There are times when WordPress developers need category data, especially the ID, while developing themes and plugins. It is not an ideal way, but sometimes, you may need to get the category ID using the Category name. In case you too are in such a situation, here is a quick code snippet to grab the ID of a category by providing the category name. The Function We can utilize the get_term_by() function from WordPress core to get the term ID, the term in this case would be our category. The functio...
2 minutes read
If you are a Web developer and still code websites compatible with a few older versions of Internet Explorer, then you must be well aware of X-UA-Compatible meta tag. Preface The X-UA-Compatible is a document mode meta tag that allows web developers to choose for what version of IE the page should render as. Below is how the tag looks like: <meta http-equiv="X-UA-Compatible" content="IE=edge"> You may provide information to the content attribute accordingly as per your requ...
2 minutes read
WordPress functions wp_enqueue_script / wp_register_script and wp_enqueue_style / wp_register_style add additional version info in the end of the JavaScript and CSS files you link (include or add) using these functions. This version info is important to ensure that the correct version of the file is sent to the browser regardless of caching. Below screenshot explains how a version number appears in WordPress enqueued scripts and styles, see the highlighted part: Preventing WordPress to add vers...
2 minutes read
We want to customize lots of things in our WordPress themes, and WordPress gallery style can be one important of those. At first, it may seem easy stuff, but actually it isn’t that easy. As a developer, you may think of customizing the look of WordPress galleries just by adding some CSS in the style.css of your theme. But that alone is not gonna work since WordPress automatically adds a default style snippet in the post that contains a gallery, which provides default styles to the gallery, and...
a minute read
WordPress featured thumbnails allow you to add a featured image to your posts. If your WordPress theme has this functionality, then you may set a featured thumbnail to your post by using the Featured Image meta box by clicking the Set Featured image link and uploading your image. The featured thumbnails generally appear in the index pages of your blog along with post body (or excerpt). Featured Image meta box in WordPress Dashboard But in case when you publish posts frequently and forget settin...
a minute read
Although WordPress traditional search doesn’t provide search quality as good as Google Custom Search, however many WordPress users still use it, as it is the default search and you don’t need to customize your theme to add search feature on your blog. Recently, a friend of mine asked me about redirecting to a post when search results have only one item. Such needs may differ from site to site, it all depends on your audience and what features you want to add to your site for their ease. In t...
a minute read
WordPress automatically adds its current Version number to the head section of the themes. If you view the source of a WordPress-based website, you may find out the WordPress version it is using. Below given is the meta tag that carries that version information and can be spotted when you right-click and view source of a WordPress site: <meta name="generator" content="WordPress 4.3.1" /> This extra information about CMS version is added by WordPress itself in order to ke...
a minute read
When you upload and add images in your WordPress posts, you might have noticed the dimensions that it adds to the image automatically. Same goes with the post thumbnails, they also carry some auto-generated thumbnail markup. The dimension markup is nothing but the width and height attributes that resize images in the post. But these dimension attributes may create problems with a responsive layout. Take a look at the highlighted section in the below given code, that’s what I’m talking about:...
a minute read
Gutenberg has brought in things which look quite interesting to enhance our editing task to another level. But I’m sure there are folks like me who don’t like adding one more external CSS file to their theme–the point here is to avoid another render block. If you are like me, you may have already noticed that style.min.css (with the ID wp-block-library-css) file popping-up in the head section of your WordPress site’s HTML. Note that this is the file which keeps the Gutenberg blocks as is...
2 minutes read
Recent posts are fine and easy to achieve, and you have many plugins to do that for you. What’s your take about recent pages? In a recent project, the client felt the need to show recent pages below every page’s content. It was something new, as nobody really asks to display recent pages on their WordPress site. So, what’s the big deal in displaying recent pages? Nothing. WordPress API is pretty flexible to display almost any kind of content you wish to on the front-end. And what does it t...