You can use wp_insert_post() function with ‘after_theme_setup‘ action hook to programatically create pages. Here is a short example,
add_action( 'after_setup_theme', 'create_form_page' );
function create_form_page(){
$title="Form";
$slug = 'form';
$page_content=""; // your page content here
$post_type="page";
$page_args = array(
'post_type' => $post_type,
'post_title' => $title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => $slug
);
if(post_exists($title) === 0){
$page_id = wp_insert_post($page_args);
}
}
Related Posts:
- How to override existing plugin action with new action
- Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
- How to store username and password to API in wordpress option DB?
- Which hook should be used to add an action containing a redirect?
- Is it worth checking if class_exists when developing a plugin and how to do it?
- Default table collation on plugin activation?
- the_content after all shortcodes are parsed
- How to auto-upgrade my plugin?
- How do I resolve Notice: Undefined offset: 0 in /wp-includes/capabilities.php on line 1145
- Category listing with thumbnail and description on home page
- How can the tinyMCE dom be manipulated (offical API does not seem to work)?
- Pass javascript result to shortcode executer function
- URLs of plugin resources?
- anything like add_meta_box for categories?
- Can we create a category list page in WordPress?
- How to include class from addon after to be sure one class exists in the main plugin?
- Developing a plug-in to charge for
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- What is the Difference between directly call a function and call a function using add_action?
- What is better way to use Bootstrap inside admin panel?
- Undefined function wp_set_password
- Updating my plugin without releasing a new version
- Is it possible to check is loaded language files correctly with WordPress plugin?
- 404 errors after plugin options update and category base change
- Default category got deleted. How to get it back as ID=1?
- How to determine, from plugin script, if active theme has The Post Title
- What allows a template file from plugin to be copied in child theme and overridden?
- add_filter : Passing an array instead of the callback function?
- creating custom archive template within plugin for custom post type using archive_template filter
- Advice on plugin structure
- Using wp_parse_args to set up Plugin Default Settings
- how to add Jquery script to one page?
- Problem with parameters in url and pagination
- get_posts() not working when accessing with a custom user role
- Trying to understand order and frequency of action hooks firing
- Where can i find wordpress auto update code flows?
- Create & Save multiple Meta-boxes
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- Do I have to worry about useState causing a re-render?
- Can’t get woocommerce_get_price_html to work [closed]
- jQuery selectors for editor elements safe to use?
- wp_set_object_terms not updating database without a die()
- WordPress form action – doesn’t work
- How to fetch only current hour posts?
- Plugin sub-menu pages recommended structure and links
- template_redirect or admin-ajax.php?
- how to get all the child category name in a specified category name?
- Widget HTML Display Problem
- Change WooCommerce Email Header using custom plugin
- Bug: Post needs to be updated twice when adding action for save_post hook
- add_submenu_page hooked function must explicitly check user capabilities – why?
- How to apply style_loader_src filter with exclusion of a specific file?
- Which is the better way to store images for the plugin?
- Issue on Checkbox with Custom Option Page
- Mixing l18n string from my plugin with WordPress’ translations
- Minimum Widget Width for Plugin Development
- Should I use wp-content/cache or [PLUGIN_DIR]/cache?
- configuration of .htaccess for add_rewrite_rule to make sense
- Restrict certain actions to plugin-specific admin menu pages only
- How to get post meta in functions?
- Adding tables to dashboard pages programmatically?
- Plugin access to average users not only admin
- how to add custom fields into new & update post page?
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- List all user post API endpoint
- Rewrite not working since upgrade to 5.9
- Condition to check previous next article post title
- How to display plugin with javascript using markup of the theme?
- Can display plugin without shortcode?
- ACF Field value in wordpress login message filter
- How to prevent wp_insert_post from creating a new post every second?
- Hook for validating and rejecting frontend image upload
- Plugin removes itself if mistake made during edit
- Using meta_key & meta_value in add_rewrite_rule
- Multisite and the JSON REST API: How to?
- Can’t create a blank template
- Custom Registration Form and Passwords
- Looping single post in a theme
- WP Ajax on page load not working on bluehost but was working on Godaddy
- Fullwidth slider using background image Flexslider WordPress
- Is there a way to tell if a shorcode’s handler is being run before or after the content formatting filter?
- How to create an embedded code for wordpress shortcode?
- How can I send an id over the url?
- grouping my widgets wordpress
- Creating custom Insert Media page
- Get fields of a widget
- How to add additional field in a table row after creating a table?
- WordPress plugin tables become corrupt
- Initialize class inside plugin
- How can i call from custom fields to the category editor?
- “Print to printer” functionality in a plugin
- How do you filter get_media_items by mime type in a custom media upload tab?
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Which subset of html does WordPress support?
- How to set init for maximum script execution, memory limit and max files upload in wordpress
- Trying to build a plugin – Cannot modify header information
- What’s wrong in the WordPress Meta Box Generator code?
- add category id to option name when adding an option on edit_category
- esc_url, esc_url_raw or sanitize_url?
- React Plugin Settings Page Localization