Don’t register your custom post type each time in WordPress

WordPress is really easy to hack into to get things done fast, but tricks to optimize WordPress aren’t that easy to find. I am here to help you optimize your code with easy to do tips.

Prevent WordPress from registering your post type on each page load

There is a function called post_type_exists( “post_type_name” ) that checks if the post type exists, it returns a boolean.

It could be used like that:

WordPress will then create (or register) the post type only once and therefore, we don’t run code that doesn’t need to be run each time someone access your site.

  • Milan Stosic

    Hm, is this suggested way to use other register functions (sidebars, etc.)?

    • nebulousGirl

      I’d say no, as no function exists to check the existence before registering except for post types.

      • Milan Stosic

        Aha, ok. Thanks for this suggestion :)