Put this in your functions.php
file:
$contact_query = new WP_Query(array(
'pagename' => 'contact',
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 1,
));
if (! $contact_query->post_count)
wp_insert_post(array(
'post_name' => 'contact',
'post_title' => 'Contact',
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => 1,
'page_template' => 'page-contact.php',
));
unset($contact_query);
What does it do?
If the contact page does not exist, create it.
Related Posts:
- Getting only direct child pages in WordPress with get_pages
- How to add a .php file to WordPress
- Help with a custom page template – listing contents of childpages?
- Custom Template 404 for specific custom post type
- How to hide all child pages with post_query?
- Populate editor with some content of a page with a page template
- Inject class in body when particular page template is used
- page-slug.php not working but only for specific slug
- How do I add my PHP app to a WordPress page whilst keeping semantic URLs?
- Create a custom theme-specific page, invisible in the admin-panel?
- Execute php in pages
- Why isn’t my link attribute getting my css?
- Sending the reset password link programatically
- Any guides on creating custom admin pages?
- Multiple is_page() in page.php
- Check if a menu is empty?
- Create WordPress pages with PHP
- load/require specific php files for specific pages/templates/post types
- Is it possible to generate a page without create in the admin?
- WordPress admin never finishes saving page on site with large page count
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Listing all sub-pages?
- Easiest way to show total number of subpages
- Passing the page ID to a login php script
- How can the plugin directory path be returned into ?
- How to enqueue CSS and JS only on specific template?
- syntax issue on php 7.4
- Can’t load WP function into external function
- Way to querry data (tags) from a wordpress database?
- Global variable $post returning incorrect object
- How to add a php custom page to WordPress
- Sort query_posts for Parent Pages to menue order or the count?
- Can’t access variable outside for loop
- My page.php shows the index.php
- How to display pictures from database?
- Change title only in dynamic page
- How can I add an area/option for a custom page description?
- How do I find PHP file that contains content of my page?
- WordPress page content outside WordPress
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- Adding wrapper elements in the_date() like in the_title()?
- How to check if the current page is at a specified path in the URL?
- Parsing Menu Items and Blog Posts
- Display all pages – in order
- trouble with page_id & highlighting current page
- Editing a PHP file to include a small text piece on every page
- What’s the best way to include PHP code in pages?
- Automatically add images to a menu
- Short code template + ajax
- Need php code’s output to display underneath a Divi Module
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Dropdown menu for categories
- Display child page content of a specific parent on home page
- Posts are not looping through correctly
- Removing custom sort order from admin page listing
- PHP Output also in Child theme, but different
- $wpdb->get_results breaking page?
- Unique PHP on each Page
- How to Display a List of Child Pages For a Parent Page in WordPress
- If is page, archive or search output this code
- WordPress Search
- Toolbar Hidden in a Virtual Page
- Display additional page templates and a sidebar on plugin activation
- Page load timer?
- Why wp_remote_get() fetches certain web pages while it doesn’t work for my localhost?
- Page not visible in ‘All pages’ after being added through PHP
- Cascading dropdown select search based on Parent Page & Child Page
- Edit and delete permissions pages and posts
- A function to get the content of a page
- Prevent header and footer from loading on specific pages with template or plugin
- Contain multiple page templates in one PHP custom template file in WordPress?
- How can I check if a post with a particular slug or title exists?
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- Category Page Displaying all Pages
- Display page content in different sections – based on page break block?
- Page template not working when logged out
- How to add a full working piece of website already coded, to a large scale Website design project?
- Child and Parent Pages list of sub pages
- How to tell if a page has subpages for Custom Post Types
- loading a php file to a specific page id
- Use page-templates without creating theme
- Get current_post in reverse order with pagination
- can’t grab PHP $_POST variable
- Newbie question. Login/Registration. New PHP page
- Adding my own custom template page but got white page
- Create page in templates for pages or the pages manager?
- Use page.php for front page
- Show results for multiple page-types
- How can I put a custom field as the link of a button shortcode?
- Display selected parts from selected pages on the frontpage?
- Adding Media button to only pages
- Tables not showing divs and loop/php items
- I want Page titles and excerpts to show up on home.php in certain order
- ACF: Echo page title when checkbox is checked
- How to refresh a template page on WordPress in 3 seconds – easiest method?
- How to handle parent and child pages?
- How do I remove blog entries from home page Twenty Eleven child theme?
- redirect user from login page if is logged
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin