Ahmed Nuaman


builder of internets ~ developer of dreams ~ tamer of Dachshunds

Fixing broken WordPress permalinks

If you’ve changed your permalink structure recently and had poop loads of 404s, you can do a few things to fix it:

Or you can save yourself a poop load of hassle and by applying a bit of cunning you can simply get around the problem with a tiny bit of code:

function _add_rewrite_rules($r)
{
    $n  = array(
        '[0-9]{4}/[0-9]{2}/[0-9]{2}/([^/]+)/?$' => 'index.php?name=$matches[1]'
    );
   
    return $n + $r;
}

add_filter( 'rewrite_rules_array', '_add_rewrite_rules' );

Simply all we do here is set an array key that’s the regex of the structure we want to redirect to the value, so in this case we’re after something like ’2009/06/29/heres-a-post-name’ and this’ll be redirect to ‘index.php?name=heres-a-post-name’. Perfect! You can read up more on WordPress’s query stuff here: http://codex.wordpress.org/Class_Reference/WP_Rewrite.

Where have comments gone?

Good question my old fruity. I'm now sticking any post discussions on Google+. Why? Well simply it's better. WordPress's comment system isn't very elegant and nor are ones like Disqus or Livefyre, so to save hassle I've just shipped them off to a social network, like a real boss.

Search

My social skills

Latest blog posts

  • Loading posts...

Subscribe in a reader

Latest tweets

  • Loading tweets...