I want to create page with shortcode when plugin is activated

register_activation_hook(__FILE__,'page_creator');

function page_creator(){
    
    $page_title="home";
    
    if(get_page_by_title($page_title)== NULL){
        
        $home_page= array(
            'post_title'     => $page_title,
            '$post_content'  => [gd_shortcode],
            '$post_status'   => 'publish',
            'post_type'      => 'page'
        );
        $insert_page = wp_insert_post($home_page);
    }
    
}


function get_shortcode(){
    $shortcode="the content to be added automatically when page is created";
    return $shortcode;
}

add_shortcode('gd_shortcode','get_shortcode');

Leave a Comment