Npcink Blog
切换菜单

前台显示编辑链接-WordPress 主题开发

一个让你更方便的方法,

本页目录7 节

edit_post_link:

显示发布的编辑帖子链接。

https://developer.WordPress.org/reference/functions/edit_post_link/

get_edit_post_link:

检索发布的编辑帖子链接。

https://developer.WordPress.org/reference/functions/get_edit_post_link/

添加于博文循环函数内

把它放在你输出 the_content()附近的主题文件中(可能在 single.php 或 page.php 文件中),以创建一个链接,你可以点击它进入管理员进行编辑。此链接仅在查看者登录并且具有编辑该页面(管理员或作者)的适当权限时才可见。

<?php edit_post_link(__('Edit This')); ?>

 有编辑权限的人(超级管理员,管理员,编辑,作者),显示编辑按钮:(推荐,来源于官方 2019 主题)

wp-content\themes\twentynineteen\template-parts\content\content-page.php

第 34 行

<?php if ( get_edit_post_link() ) : ?>
<footer class="entry-footer">
<?php
edit_post_link(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Edit <span class="screen-reader-text">%s</span>', 'twentynineteen' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
),
'<span class="edit-link">',
'</span>'
);
?>
</footer><!-- .entry-footer -->
<?php endif; ?>

 WordPress 编辑文章链接标签:edit_post_link

来源于:

https://www.beizigen.com/1687.html

WordPress 模板标签 edit_post_link 用于输出编辑文章的链接,必须用在 The Loop 主循环中。

edit_post_link( string $text = null, string $before = '', string $after = '', integer $id = 0, string $class = 'post-edit-link' )

函数参数

$text

字符串值,默认为空

链接的锚文本

$before

字符串值,默认为空

在链接前输出的文本

$after

字符串值,默认为空

在链接后输出的文本

$id

整数型,默认值:0

指定文章 ID,输出该文章的编辑链接。

$class

字符串值,默认值:post-edit-link

链接的类名

edit_post_link()函数使用示例

', ''); ?>

扩展阅读

edit_post_link()函数位于:wp-includes/link-template.php

相关函数:

参考:

About:

if( current_user_can('administrator') ) {
echo ' • 编辑';}