Snippits to improve WordPress websites

wordpress snippit
WordPress is an incredibly powerful CMS system. Not only for it’s original intent. That being a blogging platform. It has evolved over the years to be a fully rounded website creation system.

The one thing that WordPress allows you to do is, easily, customise almost anything. From the look of the website to how the pages are displayed.

This post is about one of the great things that the platform allows you to do. Customise it. Using snippits of code to modify some of the core processes. From changing the number of words that appear in the_excerpt to automatically generating the featured image in posts.

I have already covered some aspects of tweaking WordPress before with a nice search / the_excerpt snippit. This time I’m going to show you a couple of other very useful snippits that can be used to enhance WordPress easily.

They can be all added to your functions.php file of the relevant theme. Others can be used in templates as well. So to over-ride the standard features. The one that I use in template files is the first one in this list.

Change the _excerpt length snippit

A simple four lines that alter the size of the_excerpt(). Useful if you don’t want to use the default 55 words. If you want to do more things with it then have a look at the combination the_excerpt / search snippit I blogged about in the past.

Change the_excerpt default “more” snippit

By default the_excerpt uses […] to tell you that there is more to read. It isn’t a link or anything. The below alters it to a real more link to the relevant page.

Automatically generate featured images snippit

If, like this blog, you use the featured image as a nice grphical representation on what you are going to read. With this snippit, you will never again forget to add one. I have seen it used in many different ways. From the product image in eCommerce to the product image in more classical, brochure style, websites. It comes in two parts. The first selects the image to use as the featured image. This is assuming that it isn’t already set. Don’t worry, the snippit checks that there isn’t one there. If there isn’t then it generates one. The second part are the hooks into the WordPress system. The six possible actions when it comes to saving a post.

New default image size snippit

Finally, a nice one that will generate a new “default” image size. This is one that I should have put in quite a while ago as I use “half medium” sized images a lot in pseudo-galleries.

There are a lot of options available. Just head over to the codex to discover them all. I use it to set a width [ 250 pixels ] but leave the height to be determined [ 9999 ]. You can specify the height, width and how the image will be cropped. The Codex will tell you everything that you may need.

 

The below snippit is a companion piece to the above. This adds it into the size array. In other words, when you add / modify an image you will also see “Small Gallery” there along side the usual thumbnail, medium and full size images.

A nice snippit if you use the same size image a lot. I just used to resize the medium image until I discovered this snippit. It should save me a lot of bandwidth.

 

There are thousands of such snippits out there that will allow you to change almost anything in WordPress. Not only that a lot of the plugins have hooks that you can modify as well. I know, I’ve had to do it before.

Related Posts Plugin for WordPress, Blogger...