Return to Snippet

Revision: 35480
at November 9, 2010 04:43 by fjarrett


Updated Code
// Automatically Create Page When Theme Is Activated
$page_check = get_page_by_title('Sermon Media');
$page_check_id = $page_check->ID;
$new_page = array(
	'post_type' => 'page',
	'post_title' => 'Sermon Media',
	'post_status' => 'publish',
	'post_author' => 1,
);
if(!isset($page_check_id)){
	wp_insert_post($new_page);
	$new_page_data = get_page_by_title('Page Title');
	$new_page_id = $new_page_data->ID;
	update_post_meta($new_page_id, '_wp_page_template','page-template.php');
}

Revision: 35479
at November 9, 2010 04:43 by fjarrett


Updated Code
//Automatically Create Page When Theme Is Activated
$page_check = get_page_by_title('Sermon Media');
$page_check_id = $page_check->ID;
$new_page = array(
	'post_type' => 'page',
	'post_title' => 'Sermon Media',
	'post_status' => 'publish',
	'post_author' => 1,
);
if(!isset($page_check_id)){
	wp_insert_post($new_page);
	$new_page_data = get_page_by_title('Page Title');
	$new_page_id = $new_page_data->ID;
	update_post_meta($new_page_id, '_wp_page_template','page-template.php');
}

Revision: 35478
at November 9, 2010 04:41 by fjarrett


Updated Code
$page_check = get_page_by_title('Sermon Media');
$page_check_id = $page_check->ID;
$new_page = array(
	'post_type' => 'page',
	'post_title' => 'Sermon Media',
	'post_status' => 'publish',
	'post_author' => 1,
);
if(!isset($page_check_id)){
	wp_insert_post($new_page);
	$new_page_data = get_page_by_title('Page Title');
	$new_page_id = $new_page_data->ID;
	update_post_meta($new_page_id, '_wp_page_template','page-template.php');
}

Revision: 35477
at November 9, 2010 04:40 by fjarrett


Initial Code
$page_check = get_page_by_title('Page Title');
$page_check_id = $page_check->ID;

$new_page = array(
'post_type' => 'page',
'post_title' => 'Page Title',
'post_status' => 'publish',
'post_author' => 1,

);

if(!isset($page_check_id)){
	wp_insert_post($new_page);
	$new_page_data = get_page_by_title('Page Title');
	$new_page_id = $new_page_data->ID;
	update_post_meta($new_page_id, '_wp_page_template','page-template.php');
}

Initial URL
http://graphicriver.net/forums/thread/create-a-new-page-upon-theme-activation/33238?page=1

Initial Description
Simply replace 'Page Title' with your desired page title to automatically create the page when your theme is activated. Thanks to MattStrange for the original concept.

Initial Title
Automatically Create Page When Theme Is Activated

Initial Tags
wordpress

Initial Language
PHP