Following is the reformatted version of your code. get_delete_post_link()
is used for fetching delete post URL so that we dont have to worry about nonce stuff. global $post
is kept to avoid PHP notice which is currently there in your code. Please check it.
function wpso_delete_my_posts() {
global $post;
ob_start();
if ( current_user_can('delete_posts', $post->ID ) ) {
echo '<a class="delete-post" rel="nofollow" href="' . esc_url( get_delete_post_link( $post->ID ) ) . '">Delete Post</a>';
}
return ob_get_clean();
}
add_shortcode( 'delete_me', 'wpso_delete_my_posts' );
Related Posts:
- WordPress plugin shortcode not working
- Get current post id witout passing in shortcode
- How do I create a Shortcode that returns text if domain is .com, not .co.uk
- Remove specific shortcode from get_the_content()
- Autoembeds don’t work with paragraphs
- How to Output HTML tags in do_shortcode?
- Nested Shortcode Detection
- Get all posts containing a shortcode
- How to display html in a shortcode
- Videos via the video shortcode are always 640px wide?
- How to: How do I make my own shortcodes without plugins?
- Splitting Shortcode Attributes not working
- Create a shortcode in WordPress, again
- gutenberg widget outputting paragraph marks
- How to make shortcode output display where I choose
- Add Shortcode to a Div or Header [closed]
- Change link in get_terms if there is only one post in the category
- How to get total number of shortcodes in the wordpress application?
- How to change the page break numbering?
- WordPress display image link in shortcode
- stop shortcode stripping in category and archive pages
- Shortcode “post_per_page” not working
- Shortcode is running in page editor
- Creating shortcode with parameter
- Video Shortcodes not working in WordPress
- Shortcodes won’t work on live environment
- Create shortcode in Child Theme?
- Get post object in shortcode function
- How to insert image and text from admin panel throughout my theme
- Create a short code to display a specific loop
- Use shortcodes in terms description? [closed]
- How to add shortcode to HTML file (not showing on website)
- Custom Shortcode: define cursor position/insertion point?
- How to wp_redirect on ‘init’ hook on condition of current post id?
- Buddypress shortcode for tabs [closed]
- show shortcodes in editor
- Image Shortcode from ACF ID
- Page code showing in WP Dashboard
- echo do_shortcode just prints the shortcode name and not its content
- How to create a shortcode with html and php code
- PHP Running On CMS Side of WordPress
- Insert shortcode between ”
- Create a shortcode to use in visual editor
- do_shortcode doesn’t work on some pages
- Custom youtube shortcode that uses $content
- How to build dynamic pages?
- When are Shortcode Attributes Available in Template
- How to reload the shortcode content when the database is changing
- Best way to include reusable sections in page content
- Regenerating WordPress shortcodes based on value with AJAX
- Custom shortcode to display posts, first post is full
- Form shortcode with multiple options as attributes
- How to add data attributes to the wordpress audio shortcode
- Beginner’s question about shortcodes
- How to create a dropdown of shortcodes in edit mode for posts
- Multiple instances of the shortcode on the same page
- Shortcode from admin textarea to page
- do_shortcode() won’t return PHP Array
- get data with shortcode
- Replace shortcode with output in database?
- Wrap php in shortcode
- Adding my own custom woocommerce shortcode to child theme, how?
- contact form 7 :create shortcode usable in email message [closed]
- Excerpt Length & List Category Posts Plugin
- Iteratively add sub shortcodes to php array
- Show shortcode only in posts
- How to execute a shortcode?
- Shortcode, Concatenating & Parse error: syntax error, unexpected T_FOREACH
- Getting Shortcode Attributes befor content is displayed by the template
- How to remove double quotes in a shortcode?
- Shortcode to appear and show the date not code in Title and description of my website
- Colon is Missing In My Website Url in WordPress Shortcode
- Shortcode not working inside div html
- How to utilise multiple values from a single shortcode attribute?
- How to test If a post has a particular term
- Multiple shortcodes with embedded JavaScript code in same page, how?
- Contact Form 7 shortcode is commented out, but I receive spam emails from it
- Multiple values for one variable
- How can I disable(remove) wpautop (wptexturize, convert_chars) for specific shortcodes only?
- How to load specific template page in a custom shortcode
- WordPress keeps automatically inserts
- shortcode is not rendered
- nested shortcodes from different plugins. too complex? [duplicate]
- Impossible to display modification in shortcode code?
- Contact form code not working. Need help!
- How to make shortcode enabled in JSON Feeds?
- How to add a shortcode to an HTML image tag
- Automatically add class-attribute to gallery?
- Shortcode works from functions.php but not from included file
- Why can’t I type [ ] opening and closing brackets on the Visual tab?
- Video Shortcode Only Returning a Link
- Loading shortcode stylesheet only when shortcode is in text widget [closed]
- Members only Passthrough
- How to add a nested shortcode into editor?
- load plugin with ajax [duplicate]
- Can not get shortcode content in function
- Enclosing shortcodes create line breaks
- Show realtime Amazon price without API using shortcode
- Identifying first and last instance of shortcode in post
- Display a block conditionally based on user input button