Yoast Duplicate Post - Filters and actions
Filters
duplicate_post_excludelist_filter
In some cases, you might not want Duplicate Post to copy custom fields when duplicating a post. This filter allows you to filter out such fields.
In either your custom plugin or your theme's functions.php
, add the following code and filter out any custom field you don't want to be duplicated.
duplicate_post_meta_keys_filter
If you want to retrieve or alter custom fields' keys after excluding custom fields you don't want to be duplicated, you can use this filter.
In either your custom plugin or your theme's functions.php
, add the following code and filter the meta keys.
duplicate_post_get_clone_post_link
If (for some reason) you need to retrieve or alter the duplicate post link for a post, you can use this filter to do so.
In either your custom plugin or your theme's functions.php
, add the following code and retrieve or alter the post link
duplicate_post_clone_post_link
This filter is used in conjunction with the duplicate_post_clone_post_link
template tag and allows you to manipulate parts of the outputted link.
In either your custom plugin or your theme's functions.php
, add the following code and retrieve or alter the post link's HTML
Now, any time you call the duplicate_post_clone_post_link
in your theme, the outputted link will always be wrapped in our custom div tag.
duplicate_post_enabled_post_types
If (for some reason) you need to alter the list of post types for which the plugin is enabled, you can use this filter to do so. It is called after the value for the option has been read from the database, so it can be used to override the settings or to enable post types that are not displayed in the Options page.
For example, in either your custom plugin or your theme's functions.php
, add the following code to enable the plugin for the product
post type:
Now, any time you call the duplicate_post_clone_post_link
in your theme, the outputted link will always be wrapped in our custom div tag.
Actions
duplicate_post_pre_copy
This action is called right before cloning of the post or page starts.
In either your custom plugin or your theme's functions.php
, add the following code if you want to hook into this action.
duplicate_post_post_copy
This action is called right after cloning of the post or page starts.
In either your custom plugin or your theme's functions.php
, add the following code if you want to hook into this action.
dp_duplicate_post
This action is called right after the WordPress standard fields of a post, or a non-hierarchical custom type item, have been copied. Duplicate Post itself hooks some functions to this action to copy custom fields, taxonomies, attachments, comments etc.
This action has the following parameters:
$new_post_id
(int) - The newly created post's ID.$post
(WP_Post) - The original post's object.$status
(string) - The destination status as set by the calling method: e.g. ‘draft’ if the function has been called using the “New Draft” links. Empty otherwise.
In either your custom plugin or your theme's functions.php
, add the following code if you want to hook into this action.
dp_duplicate_page
This action is called right after the WordPress standard fields of a page, or a non-hierarchical custom type item, have been copied. Duplicate Post itself hooks some functions to this action to copy custom fields, taxonomies, attachments, comments etc.
This action has the following parameters:
$new_post_id
(int) - The newly created post's ID.$post
(WP_Post) - The original post's object.$status
(string) - The destination status as set by the calling method: e.g. ‘draft’ if the function has been called using the “New Draft” links. Empty otherwise.
In either your custom plugin or your theme's functions.php
, add the following code if you want to hook into this action.