Stop WordPress adding <p> tags in code elements

WordPress has a tendency to sprinkle an abundance of p tags in your blog posts wherever you have lots of spaces between paragraphs. In most cases it is exactly what you want. You want the paragraph spacing to be nice and consistent. But there are times it works against you. I tend to put all code extracts in my blog posts in code tags. I use css to style any code that should be a block. The problem is code tends to have consecutive line breaks. Wodpress goes and separates the codeblock where it finds more than one line-break and wraps them in a p element.

So, what do you do? Well, the solution is the wp-includes/formatting.php in a function called wpautop(). Apart from finding a whole bunch of pee jokes in this function (with variable names like pee and tinkle), you will see that it cleans up line breaks and replaces a lot of them with P tags. You will also see that pre tags are treated specially.
Continue reading “Stop WordPress adding <p> tags in code elements”

Changing the ‘WordPress Address URL’ of your blog the hard way

Follow the steps shown here if you can no longer access the admin site of your wordpress blog.

If you have accidentaly (or stupidly 🙂 ) changed the WordPress Address of your blog to an incorrect value, you’ll find out that you can no longer access the admin console to change it back. To fix it you have two options:

  • Temporary PHP change
  • Direct database change

Continue reading “Changing the ‘WordPress Address URL’ of your blog the hard way”

WordPress and google webmaster tools sitemap

If you are trying to use your wordpress feed as your sitemap in google webmaster tools, and it looks like there are errors in lines 11 and 12 citing Invalid URL, Invalid XML: too many tags, and Incorrect namespace, it is because you are using your rss2 feed as the sitemap

If you are trying to use your wordpress feed as your sitemap in google webmaster tools, and it looks like there are errors in lines 11 and 12 citing Invalid URL, Invalid XML: too many tags, and Incorrect namespace, it is because you are using your rss2 feed as the sitemap.
Continue reading “WordPress and google webmaster tools sitemap”

Highlighting author comments on WordPress

How to highlight comments made by the article author in your blog. This method doesn’t use hard coded emails making it flexible and easier to implement. It also uses IDs so the comments can’t be faked.

When I was looking for a way to highlight the author comments in this wordpress template I was creating, I had a search on google. Most of the results were Continue reading “Highlighting author comments on WordPress”

WordPress Template Quirks

If you edit any of the wordpress system files or even just the functions.php of a template, make sure there are no spaces before the <?php or after the ?>.

If you do, it’ll just cause you grief. Some pages will be visible while others will have the following error:

Cannot modify header information - headers already sent

I guess it happens because functions.php is included before it sets the http headers. I haven’t looked at the code enough to figure out where the header is written, so no leading or trailing spaces in wordpress system php files!