[ Tag Archive ]
Find the Category ID using the Category Slug in WordPress
This is a quick little piece of code that I have been using a lot lately. I needed to get the category ID but all I had to work with was the category slug. Luckily WordPress has a neat little function called get_term_by() which makes it super easy. The function can be used to get a lot more information but for this example I am just going to extract the ID.
Using PHP to Remove an HTML Tag from a String
There are times when you need to strip one specific HTML tag from a string and the PHP function strip_tags() doesn’t work the way you want it to. strip_tags() allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags? Especially when you can use preg_replace().
Quick & Easy Excerpt Mods Coming in WordPress 2.9
I just stumbled across these two little pieces of code and thought that they might be useful to some people out there who want to mess around with the default settings for the_excerpt() function in WordPress. The first one gives you the power to change the number of words displayed by the function the_excerpt(), and yes, you can have more than 55 words. The second piece of code allows you to change the trailing [...] that appears at the end of your excerpt.
Display Random Posts in WordPress
I am working on a new WordPress site and I wanted to display a selection of random posts at the bottom of every page. It is pretty simple to do, but I also wanted to make sure that on single post pages, the current post would be excluded. That took a little bit more figuring out but I got it working.
Check if a Number is Even or Odd with PHP
Ever needed to check if a number is even or odd? If so, here is a pretty simple piece of code that does just that.





