Author: Thomas

  • Don’t use strlen()

    Don’t use strlen()

    Each time I see someone use strlen() I cringe. It will break. Despite its name, strlen() doesn’t count characters. It counts bytes. In UTF-8 a character may be up to four bytes long. So what happens if we use strlen() and its companion substr() to shorten the title of post? <?php # -*- coding: utf-8…

  • Implement a 404 image in your Theme

    Implement a 404 image in your Theme

    Every good Theme comes with a 404.php for requests that don’t match any post or page. But what to do with missing images? They are requested per an <img> element usually, your visitors may never see the HTML template. Let’s use a 404 image. I put the following code on top of my 404.php before…

  • Pretty permalinks without mod_rewrite

    Pretty permalinks without mod_rewrite

    There are still some third-class web hosters who do allow the .htaccess files … and turn off the standard module mod_rewrite. But without mod_rewrite, WordPress cannot use pretty permalinks, right? Wrong! There’s another directive we can use: ErrorDocument. ErrorDocument 404 /index.php This will do almost the same as the rewrite rules WordPress offers. It will…

  • Advent Calendar- How to disable comments for WordPress pages in any theme

    Advent Calendar- How to disable comments for WordPress pages in any theme

    Usually you don’t need comments on pages. Unfortunately, WordPress doesn’t offer a separate option to leave comments on posts on and turn them off for pages. If your theme calls comments_template(); in its page.php and you don’t want to break automatic updates, you cannot just remove the function call, because it will be overwritten with…