Performance: Registering custom post types
MEDIUM IMPACT
This affects page load speed and server response time by adding new content types that WordPress must recognize and handle.
<?php
function register_my_cpt() {
register_post_type('book', array(
'labels' => array('name' => 'Books'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'supports' => array('title', 'editor'),
));
}
add_action('init', 'register_my_cpt');
<?php
function register_my_cpt() {
register_post_type('book', array(
'labels' => array('name' => 'Books'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields', 'comments', 'revisions', 'author'),
));
}
add_action('init', 'register_my_cpt');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Register CPT with many supports | More meta boxes added to DOM | Multiple reflows due to complex admin UI | Higher paint cost from extra UI elements | [X] Bad |
| Register CPT with minimal supports | Fewer DOM nodes in admin UI | Single reflow with simpler UI | Lower paint cost | [OK] Good |