WordPress在前台添加删除文章功能

前段时间在开发WordPress主题用户中心功能的时候,需要在网站前台添加一个删除文章的功能,简单搜索了下,发现网上相关的WordPress教程还是很多了,于是记录下来。

这个功能还是很方便好用的,添加在文章的循环里面就可以实现WordPress前台删除文章功能。

将下面代码添加到自己的WordPress主题文件位置即可。

<?php   
$url = get_bloginfo('url');   
  if (current_user_can('edit_post', $post->ID)){   
    echo '<a class="delete-post" href="';
    echo wp_nonce_url("$url/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID);  
    echo '"><strong>删除文章</strong></a>';   
  }   
?>

发表评论

邮箱地址不会被公开。 必填项已用*标注