Criar uma página ou post programaticamente após a ativação do tema

Você precisará deste código se quiser criar uma página após a ativação do tema. Tudo que você precisa fazer é adicionar este código diretamente ao arquivo function. do seu tema.

add_action( 'after_switch_theme', 'insert_page_on_theme_activation' );
function insert_page_on_theme_activation() {
    $page_slug = 'test-page-title'; // Slug of the Post
    $new_page = array(
        'post_type'     => 'page',               // Post Type Slug eg: 'page', 'post'
        'post_title'    => 'Test Page Title',    // Title of the Content
        'post_content'  => 'Test Page Content',  // Content
        'post_status'   => 'publish',            // Post Status
        'post_author'   => 1,                    // Post Author ID
        'post_name'     => $page_slug            // Slug of the Post
    );
 
    if (!get_page_by_path( $page_slug, OBJECT, 'page')) { // Check If Page Not Exits
        $new_page_id = wp_insert_post($new_page);
    }
}

Dúvidas? Faça um comentário logo abaixo ou envie uma mensagem clicando aqui.

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *