How to Duplicate a Page or Post in WordPress

How to Duplicate a Page or Post in WordPress

Duplicating a post or page within WordPress is more than just copying and pasting content. It is also possible to save the template for your page as well as SEO information and images, to speed up the process of designing your website or reworking your content.

Fortunately, duplicated pages and posts as well as all associated data within WordPress can be done easily. There are a few methods of getting the job done using and without plugins.

In this post we’ll discuss ways to make an WordPress duplicate page copy, or post in a safe manner, and also provide some plugins to assist. Let’s get started

It is easy to duplicate a page on WordPress by using these Plugins

Cloning a page on WordPress is easy using the WordPress plugin because everything is handled within your dashboard. The plugins also provide the best way to duplicate a page or page since you’re not altering the code of your website directly.

If you’re in search of the perfect instrument Here are four plugins worth looking into.

Duplicate Post One of the most popular choices to use for WordPress blog and page copying can be Duplicate Post. The popular plugin is simple to use and copies everything from the contents of the post or page to the comments that accompany it. It also provides the option of a suffix or prefix to distinguish the original post from the copy.

To duplicate the content of a WordPress post using this program, simply have to:

  1. Install and then activate the plugin and then activate it.
  2. On Your WordPress dashboard, click the Posts >> All when cloning posts, or Pages All when you are cloning posts and Pages > All when you are cloning pages.
  3. Go to the page or article you want to copy and then click Clone in order to duplicate it.
  4. Multiple pages or articles can be selected and you can even clone them all in one go using bulk actions.
  5. Duplicate Page and Post

Duplicate Pages and Posts doesn’t have many options however it does make up for it in speed. The lightweight duplicate post plugin is among the fastest methods of cloning the content of a page or post within WordPress it doesn’t make your website more bloated by requiring excessive bells and bells.

To copy an article or page using this plugin, follow the steps below:

  1. Install and then enable the plugin and then activate it.
  2. Click on the Posts >> All All or Pages > All depending on the type of duplicate you’re looking for.
  3. Click on the page or post that you want to duplicate.
  4. Choose to open the duplicate option.
  5. Duplicate Page

Duplicate Pages includes a couple of extra options that other cloning softwares don’t offer. The plugin duplicates pages, posts and post types that you have created. You can also save the duplicates as drafts or pending, public or private.

To make use of Duplicate Page you only must:

  1. Install and then activate the plugin and then activate it.
  2. Set it up to meet your requirements.
  3. Click on Pages > All or Posts > All to find the post you wish to duplicate.
  4. Choose the Duplicate option. option.
  5. Post Duplicator

Another easy cloning tool can be found in Post Duplicator. This plugin makes an exact copy of any page or post that you want to duplicate, which includes custom fields, post types as well as custom taxonomies. It’s simple and quick to use, and won’t affect the quality of your website.

To duplicate content using this tool to duplicate content, follow these steps:

  1. Install the plugin and then activate it.
  2. Go to Pages and then click all and Pages > All to locate the content you wish to copy.
  3. Move your cursor over the page or post.
  4. Select to select the Duplicate page as well as the Duplicate Post option.

Duplicating a Page in WordPress Without a Plugin

Of course, there is no need to make use of a plugin to copy the content of a post or page in WordPress. You can do it by hand, either by changing in the funtions.php file or by copying and pasting relevant code. Let’s examine the ways to accomplish this.

  1. Allow Cloning to be performed via funtions.php Code

One of the methods to copy the content of a WordPress post or page is to alter the code within the functions.php file. Although this is a simple thing to achieve, you need to be extra cautious and create backups of your site before you start.

To allow cloning of posts, you’ll have to open the functions.php file and edit it, via Secure File Transfer Protocol (FTP) or whatever other method you’d prefer to use. You’ll then have to include this code in a snippet at on the last line of your file.

/*

* Function to duplicate posts. Dups appear as drafts. Users are redirected to edit screen

*/

function rd_duplicate_post_as_draft(){

Global $wpdb database;

If (! ( isset( $_GET[‘post’]) || isset( $_POST[‘post’]) || ( isset($_REQUEST[‘action’]) && ‘rd_duplicate_post_as_draft’ == $_REQUEST[‘action’] ) ) ) {

wp_die(‘No duplicate post was supplied! ‘);

}

/*

* Nonce verification

*/

if ( !isset( $_GET[‘duplicate_nonce’] ) || !wp_verify_nonce( $_GET[‘duplicate_nonce’], basename( __FILE__ ) ) )

return;

/*

* Get the post ID from the beginning.

*/

$post_id = (isset($_GET[‘post’]) ? absint( $_GET[‘post’] ) : absint( $_POST[‘post’] ) );

/*

* and all of the original post information then

*/

$post = get_post( $post_id );

/*

* If you don’t wish for the your current user to become the new author of the post,

* Then change the next couple of lines as follows the following: $new_post_author = $post->post_author

*/

$current_user = wp_get_current_user();

$new_post_author = $current_user->ID;

/*

* If post data is present and the post duplicate is needed, then create it.

*/

If (isset( the $post ) and $post= null) {(isset( $post) && $post!= null)

/*

* Post data array with new post date

*/

$args = array(

‘comment_status’ => $post->comment_status,

‘ping_status’ => $post->ping_status,

‘post_author’ => $new_post_author,

‘post_content’ => $post->post_content,

‘post_excerpt’ => $post->post_excerpt,

‘post_name’ => $post->post_name,

‘post_parent’ => $post->post_parent,

‘post_password’ => $post->post_password,

‘post_status’ => ‘draft’,

‘post_title’ => $post->post_title,

‘post_type’ => $post->post_type,

‘to_ping’ => $post->to_ping,

‘menu_order’ => $post->menu_order

);

/*

* insert the post using the wp_insert_post() function

*/

$new_post_id = wp_insert_post( $args );

/*

* find all current post terms and change them to the latest post draft

*/

$taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array(“category”, “post_tag”);

foreach ($taxonomies as taxonomies as) {foreach ($taxonomies as $taxonomy)

$post_terms = wp_get_object_terms($post_id, $taxonomy, array(‘fields’ => ‘slugs’));

wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);

}

/*

* duplicate all meta post only within two SQL queries

*/

$post_meta_infos = $wpdb->get_results(“SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id”);

if (count($post_meta_infos)!=0) {

“$sql_query” is “INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) “;

Foreach ($post_meta_infos in $meta_info) {foreach ($post_meta_infos as $meta_info)

$meta_key = $meta_info->meta_key;

if( $meta_key == ‘_wp_old_slug’ ) continue;

$meta_value = addslashes($meta_info->meta_value);

$sql_query_sel[]= “SELECT $new_post_id, ‘$meta_key’, ‘$meta_value'”;

}

A $sql_query.= implose(” UNION ALL ” $sql_query_sel);

$wpdb->query($sql_query);

}

/*

* Lastly, go to the edit screen to see the latest draft

*/

wp_redirect( admin_url( ‘post.php?action=edit&post=’ . $new_post_id ) );

exit;

else Other than that,

wp_die(‘Post creation failed, couldn’t find an original post: . $post_id);

}

}

add_action( ‘admin_action_rd_duplicate_post_as_draft’, ‘rd_duplicate_post_as_draft’ );

/*

• Add duplicate links in the action list for post_row_actions

*/

function rd_duplicate_post_link( $actions, $post ) {

if (current_user_can(‘edit_posts’)) {

$actions[‘duplicate’] = ‘Duplicate’;

}

return $actions

}

add_filter( ‘post_row_actions’, ‘rd_duplicate_post_link’, 10, 2 );

To allow cloning of pages, make use of the same code, but change the line ending by:

add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2);

Once you have done that, you can save the file and upload onto your website. You can then go over to the WordPress dashboard. The duplicate button will now be displayed whenever you click on a page or a post you’d like to duplicate.

  1. Manually Copy & Paste Code to Duplicate a Page

If you do not wish to modify the functions.php file, you can cut and past the code of the post or page you wish to copy. To accomplish this, you’ll have to:

  1. Go to the page or post that you would like to duplicate.
  2. Go to the More Tools & Options menu.
  3. Select Code Editor.
  4. Copy the code to the post or page.
  5. Click on New Post or New Page.
  6. In the post’s new page, you can open Code Editor. code editor.
  7. Copy the code.
  8. Go to the More Tools & Options menu.
  9. Select Visual Editor.
  10. This new webpage or blog post should have a clone or copy of the previous one.

The process could take some time, and you’ll have to do it separately for each article or page you’d like to duplicate. This is why we suggest making use of an WordPress duplicate-page plugin when you’re planning to duplicate lots of pages or posts.

 

Leave a Reply