Categories: WordPress

How To Create Page Using Hook

In this topic, We are going to see that How to create a page using the hook.

Here we use the wp_insert_post function to create a new page dynamically,

==> Add the below code in the function.php file of your child theme or your plugin file.

function add_new_page(){
  $my_page = array(
    'post_type'     => 'page',
    'post_title'    => 'New page',
    'post_content'  => 'This is my New page.',
    'post_status'   => 'publish',
  );
  wp_insert_post($my_page);  
}
add_action('init','add_new_page');

Here, the init hook is used for the add page.

Please check the below image:

Thank You, hope you guys found something useful.

Mitali Kukadiya

I am a Junior WordPress Developer at Vision Infotech. I have good skills in WordPress, PHP, HTML, CSS, and jQuery.

Share
Published by
Mitali Kukadiya

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago