PHP snippet · Admin & Dashboard

Duplicate posts and pages

Adds a Duplicate link to the row actions on posts, pages, and custom post types. Copies content, custom fields, and terms into a fresh draft.

About this php snippet

Adds a Duplicate action to the row hover menu in Posts and Pages. The copy is created as a draft, titled with a copy suffix, owned by whoever clicked, and you land straight in the editor on it.

Custom fields and taxonomy terms come across, which is what makes this useful with a page builder. An Elementor or Gutenberg layout lives in post meta and post content, so the duplicate is a real working copy you can start editing, not an empty shell with the right title.

What it does

  • Adds a Duplicate link to the row actions on posts, pages, and any custom post type
  • Copies the title, content, excerpt, parent, menu order, every custom field, and every taxonomy term
  • Creates the copy as a draft owned by the person who clicked, then opens it in the editor

Good to know

  • The action is nonce-checked and gated on edit rights for the item being copied, so it cannot be fired by a crafted link
  • The two edit-lock meta keys are skipped on purpose. Copying them makes the new draft claim that somebody else already has it open.
  • Meta values are unserialized before being written, so a stored array is saved as an array rather than as a string of itself. Get that wrong and a duplicated Elementor page opens broken.
  • The copy is always a draft, so nothing goes live by accident

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.