Im trying to add a page programmatically to a store by installing my plugin. I tried to create a template but it seems to be the wrong way. can someone help ? thanks I DO DONT need a tamplate, i need to add a page to my store.

EDIT I had created a page with

$title = __( 'Bogin' );
if ( NULL == get_page_by_title( $title ) ) {
$post_id = wp_insert_post(
        'post_name'      => 'bogin',
        'post_title'     => $title,
        'post_content'   => "some content",
        'post_type'      => 'page',
        'comment_status' => 'closed',
        'ping_status'    => 'closed',
        'post_status'    => 'publish',

and now i can controll the content of that page use html & javascript. Im planing to put a relly big file in there. am I need an other way to do so? can I change the size of the file 'page_content' in table 'wp_post' by code ? i would like to find a way to do it by code beacuse that when i save a big string there the site creashed

  • This is the third time you’ve asked this question. – Jacob Peattie May 17 '18 at 10:02
  • 1
    Possible duplicate of how to redirect to my template – Jacob Peattie May 17 '18 at 10:03
  • in that question I asked about a template – bogin May 17 '18 at 11:14
  • You’re clearly asking how to do the same thing 3 different ways. – Jacob Peattie May 17 '18 at 12:59
  • Im cleary need help, but no, I andersted to ask about page insted of template from the comments, YOU r clearly dont want to help, so why interrupt ? – bogin May 17 '18 at 13:33

You can use the activation hook and call function wp_insert_post()

class MyPlugin {
    static function install() {
        $my_post = [
            'post_title'    => 'My page title',
            'post_content'  => 'My page content',
            'post_status'   => 'publish',
            'post_author'   => 1, // Set author id here
            'post_type'     => 'page',
        wp_insert_post( $my_post );
register_activation_hook( __FILE__, [ 'MyPlugin', 'install' ] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.