I am trying to:
Duplicate post on front end. I follow the solution explained in support thread
https://toolset.com/forums/topic/duplicate-custom-posts-at-front-end/
However, I get an error "Fatal error: Uncaught Error: Call to undefined function add_shortcode() ".
Hi, that ticket is a bit outdated. Did you add code to your theme's functions.php file (note it is supposed to be added in functions.php with an "s" at the end), or to a custom code snippet in Toolset > Settings > Custom Code? Can you copy + paste the exact code you added?
function duplicate_posts() {
duplicate_post_clone_post_link( __('Clone this Post','duplicate-post'), $before, $after, $id );
}
add_shortcode( 'duplicate_post', 'duplicate_posts' );
I have added it to functions.php
Normally that error message occurs if you try to execute WordPress code in PHP without loading WordPress. Are you doing any custom AJAX, or loading a PHP file directly without loading WordPress? For example, this person is using a PHP file to display some images. They tried to use add_shortcode inside this PHP file, without loading WordPress code: https://wordpress.org/support/topic/getting-call-to-undefined-function-add_shortcode-for-refreshing-a-div/
I have removed the code from the functions.php and added it to toolset Custom Code. The error is not appearing now but when I add the short code to the content template it will not show link to duplicate the post.
My issue is resolved now. Thank you!
Yes the code Shane shared appears to be an incomplete example. I see you have marked the ticket resolved, do you still need assistance? If so, please reopen the ticket or add a comment here.