Due to updates, over time, that have been made to the site and the age of this article, this post may not display correctly. In particular images may be missing or product reviews display incorrectly.

If this is the case and you'd particularly like me to fix it, then please reach out to me on Twitter.

A while ago I realised that I had a need to be able to turn off particular content on and off, as required, on particular posts and pages. In this case, it was to switch off comments and/or advertisements (they default as being switched on). For example, you may have an “About Me” page on which you may not want people to be able to leave comments.

The solution was quite simple and makes use of the custom fields feature.

First of all, find the code that you need to find switchable within your theme page and add the following before it…

And immediately after it…

What this does is look for a custom field named “nocomment”. If it exists and doesn’t contain “Yes” then it will execute the code in question. Obviously, you can change the field name as you require – make sure you change the reference in the above code as well.

I have another, titled “noad”, which I then use for turning off advertisements on particularly pages.