PHP Code Broken in WordPress

I just spent the last few days trying to figure out something odd. When I pasted certain lines to post in WordPress, it would cause a 503 error. I eventually narrowed it down to a few particular lines in my last example:

$mydebug = fopen('debug.txt','a'); in a post it causes a 503 error
$file_contents = curl_exec($ch);
fwrite($mydebug,"/nHttp Code: $httpCode/n");

Each one would throw a Service Unavailable 503 error. I got around the problem by tossing a space between the parenthesis and semi-colon but it still bothered me.

Turns out it wasn’t WordPress at all, but rather the Apache module mod_security. This post tells the whole story. The quick fix is to create/modify your wp-admin .htaccess file to include:

SecFilterEngine Off

After that I could easily post this message without flubbing my code.

SEO Friendly Titles for WordPress

The standard theme for WordPress doesn’t include very pretty titles. One of the things you can do to optimize readability for users coming in from search engines or bookmarking your page is to clean up your titles. It’s actually pretty easy to do.

We’ll start with the default Krubrick title. This is located in your Header.

<title><?php bloginfo('name'); ?> <?php if (is_single()) { ?>&» Blog Archive <?php } ?><?php wp_title(); ?></title>

A little bland. First off our sitename comes first. Llynix.com doesn’t really convey anything, the juicy information is in the title. In addition with this scheme the home page, 404 page and search pages get a default ‘llynix.com’ as their title.

We need something better. Happily, it doesn’t take much.

  <title>
<?php 
  if (is_single()) { ?>» Blog Archive <?php } 
  if (is_home()) { ?>Home<?php } 
  if (is_404()) { ?>404 Not Found<?php }
  if (is_search()) { ?>Search Results for <?php the_search_query(); }
?>
<?php wp_title(); ?> | <?php bloginfo('name'); ?>
  </title>

Now depending on what we are viewing our page title changes. Also our page title comes first, with the site name after the pipe (|).