Skip to content

Instantly share code, notes, and snippets.

@davidperezgar
Created January 14, 2015 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidperezgar/4e1ca49d12c34876d426 to your computer and use it in GitHub Desktop.
Save davidperezgar/4e1ca49d12c34876d426 to your computer and use it in GitHub Desktop.
Create Wordpress Pages when activates a theme
//Página de creación automática
if (isset($_GET['activated']) && is_admin()){
$new_page_title = 'Título de la página';
$new_page_content = 'Aquí va el contenido de la página, por supuesto puedes añadir HTML a voluntad';
$new_page_template = ''; //nombre del archivo de plantilla de página personalizada, por ejemplo: plantilla-personalizada.php. Déjalo en blanco si no quieres crear una plantilla de página personalizada.
//No cambies el código que viene a continuación a menos que sepas realmente lo que estás haciendo
$page_check = get_page_by_title($new_page_title);
$new_page = array(
'post_type' => 'page',
'post_title' => $new_page_title,
'post_content' => $new_page_content,
'post_status' => 'publish',
'post_author' => 1,
);
if(!isset($page_check->ID)){
$new_page_id = wp_insert_post($new_page);
if(!empty($new_page_template)){
update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment