Do you usually make WordPress Duplicate Page things on our site?
Duplicating a page or post is not something very common when you develop a website. However, it would be a smart move of you if you usually duplicate pages or posts.
Thus, do you need a testing field for a brand new layout? Or maybe for system updates and upgrades? No matter what the situation is, you can always make WordPress duplications by many methods. What you need to notice here is which methods will suit you and your site. In this article, we are very pleased to deliver you the tutorial to explain and guide how to duplicate a page in WordPress.
Before that, let’s get things up: why you should make page/post duplications.
Table of Contents
WordPress Duplicate Page: Do You Need It?
Well, you can choose to do it or not. However, there are situations where you will need your site’s duplications, for instance:
– Users are working on the newest version of the theme, plugin, WordPress, PHP, or something related and your site doesn’t have the staging process.
– Want to make a copy to reuse when you make new content.
– You find a dream layout and you would like to try it on your site.
– Need to apply a custom CSS/HTML code to your new website.
As you can see, a duplicated version will bring into play enormous benefits. Well, let’s dip into the methods to duplicate page WordPress.
Manual Copying and Pasting the Content
Simply, you will copy and paste the content into a new version/draft. It looks very easy to approach and we can guess why you choose this method:
– You don’t know the faster method.
– Your site does not own many pages and does not focus on SEO.
– You are duplicating a page that is inaccessible through your site’s back end.
For reasons 2 and 3, we have to agree that copying and pasting hand by hand become the best choice for all of you. Still, this method has some cons. You can’t copy pictures, meta tags, permalinks, custom CSS/HTML, and other elements correctly.
Here are 2 steps to do it:
Step 1: Make a Copy Version from the Original Source
Well, you can say that Ctrl+A will be the most important factor here. What you will do is get access to the planned site, highlighting, copying, and pasting it to your planned project.
Therefore, you will go straight for the content. Move to the next step.
Step 2: Delete Tags in the HTML
After pasting the content, navigate to your site’s code editor. In here, you will delete all and <span> Meta tags since your site will follow the framework of the code.
As has been said, duplicating manually may bring you potential bugs and errors. To solve this, you may look up other resolutions that still maintain our site.
Duplicating Posts and Pages with Block Editor
Particularly, duplicating with the Block Editor seems semi-manual but it still has almost the same disadvantages as manual duplicating.
You may begin by opening the website and selecting “More tools & choices” from the menu in the upper right corner. Choose “Tools” and “Copy all contents” after that. After pasting everything into the designated section, you will then have all of the material for the new project.
Applying a Plugin in the WordPress Duplicate Page
Generally, you can do anything in WordPress with plugins and so does page duplications.
First, you will select the suitable plugins: updated within the last 6 months, rated at least 4/5 stars, and can integrate with your WordPress version. Let’s take the Duplicate Page plugin as an example.
Then, you will download and activate it. Navigate to “Pages” -> “All pages”, move to the planned site, and choose the “Duplicate this” button. Well done, you can duplicate a page in WordPress with plugins from now.
Importing Code to the File functions.php
People often say “The tougher the solution is, the more flexible and efficient the result will come out”. On the other hand, this answer fits with this saying as well. Users may add code to the functions.php file to accomplish a variety of goals in addition to duplicating a WordPress page. You might provide a link on the dashboard tab to make things easier. So, creating a WordPress clone page will be quite simple for you.
Let’s settle down some requirements first:
– Your site’s server accessibility: You can always find the references in the host management panel or in an email sent to you when buying an account for the 1st time.
– A child theme coming from the current parent theme: You can save changes when updating/upgrading the site. Also, your site should have a child theme.
– A text editor: You should choose the suitable one for your purposes.
– A FTP client: Users may access the FTP client in the hosting’s file manager. Besides, you can also use other implements.
Access the FTP Clients
First of all, access the FTP client and navigate to the folder “wp-content” -> “theme”. Thus, you should have the file functions.php in the child theme’s folder. If not, make one first.
Add Code Lines
Afterward, open that file. In there, you will add the below code lines:
/* Duplicate posts and pages function. Duplicates appear as drafts, and the user is redirected to the Edit screen. */ function rd_duplicate_post_as_draft(){ global $wpdb; if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) { wp_die('No post to duplicate has been supplied!'); } /* Nonce verification */ if ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) ) return; /* This gets the original post or page ID */ $post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) ); /* …then grabs the original post data. */ $post = get_post( $post_id ); /* To select another user as the post author, use $new_post_author = $post->post_author;. Otherwise… */ $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; /* If the post data exists, create the duplicate */ if (isset( $post ) && $post != null) { /* Create a new post data array */ $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 wp_insert_post() */ $new_post_id = wp_insert_post( $args ); /* Get all current post terms, then set them against the new draft. */ $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); 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 of the post metadata */ $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 = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; 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'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } /* Redirect to the Edit post screen for the new draft */ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } add_action( 'admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft' ); /* Add the duplicate link to the action list for post_row_actions */ function rd_duplicate_post_link( $actions, $post ) { if (current_user_can('edit_posts')) { $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>'; } return $actions; } add_filter('post_row_actions', 'rd_duplicate_post_link', 10, 2 ); add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
Finish the Process
Lastly, reload and get back to the screen “Pages”. On that screen, you should observe the link of duplicating on this page. Furthermore, you can use this as a plugin and develop it for later uses.
Therefore, that’s how to duplicate page in WordPress with a plugin.
Choosing the Rightful Ways for WordPress Duplicate Page
You may think that it’s quite easy to copy page WordPress. Besides, people tend to choose the best and fastest ways to get it done. However, we suggest you should choose a more complex and detailed method based on your demands.
Therefore, using a plugin is the best option for those who only need to copy a WordPress page. When you download and install your theme, it will go into action and provide all features for all associated issues. The hardcoding approach could be a good option, though, if you want to produce a lot of copies. On the other hand, if it’s possible, you can pursue different options for certain reasons and objectives. Hence, if it fully helps you, it will be worth your budget.
How to Duplicate a WordPress Page: Conclusion
Going at the situation, creating a WordPress duplicate page should be simple for any site developer or owner. Each person has a variety of options depending on the requirements and level of experience. After reading this guide, you should know how to clone a WordPress post or page using 4 popular techniques. Their challenges range in complexity from the most basic to the most advanced.
Through the article, we believe you would have obtained the rightful solution to duplicate a WordPress page.
Read more: How to Create a WordPress Child Theme.