WordPress.org

Support

Support » How-To and Troubleshooting » create a custom page on theme activation

create a custom page on theme activation

  • I want to create a page with a custom template automatically upon theme activation. Is this possible?

    I think it can be done as wordpress has default about me page.

    Can anyone show me some way?

Viewing 1 replies (of 1 total)
  • Hi,

    You can add something like this in the functions.php file.

    if ( is_admin() && isset($_GET[‘activated’] ) && $pagenow == “themes.php” ) {
    global $wpdb;

    $sql = “

    INSERT INTO $wpdb->posts (

    ID ,

    post_author ,

    post_date ,

    post_date_gmt ,

    post_content ,

    post_title ,

    post_excerpt ,

    post_status ,

    comment_status ,

    ping_status ,

    post_password ,

    post_name ,

    to_ping ,

    pinged ,

    post_modified ,

    post_modified_gmt ,

    post_content_filtered ,

    post_parent ,

    guid ,

    menu_order ,

    post_type ,

    post_mime_type ,

    comment_count

    )

    VALUES (

    NULL , ‘1’, ‘0000-00-00 00:00:00’, ‘0000-00-00 00:00:00’, ‘aaa’, ‘page-title’, ”, ‘publish’, ‘open’, ‘open’, ”, ‘page-title’, ”, ”, ‘0000-00-00 00:00:00’, ‘0000-00-00 00:00:00’, ”, ‘0’, ”, ‘0’, ‘page’, ”, ‘0’

    )

    “;

    $wpdb->query($sql);

    $page_id = $wpdb->insert_id;

    $sql = “insert into “. $wpdb->postmeta . “(post_id, meta_key, meta_value) values($page_id, ‘_wp_page_template’, ‘custom-template.php’)”;

    $wpdb->query($sql);

    }

Viewing 1 replies (of 1 total)
  • The topic ‘create a custom page on theme activation’ is closed to new replies.
Skip to toolbar