【问题标题】:In WordPress how can I add text next to the Page tile, with (no title) as the title, in admin panel?在 WordPress 中,如何在管理面板中以(无标题)作为标题的页面磁贴旁边添加文本?
【发布时间】:2019-06-06 14:58:08
【问题描述】:

如何在 WordPress 管理面板中的页面标题旁边添加此文本?我从高处和低处搜索,似乎没有人给出正确的答案。

我也在 GitHub 上找到了这个 sn-p,但它似乎是基于页面标题名称而不是帖子 ID 或其他内容。如果我有多个没有标题的页面,即。 “(no-title)”这个sn-p不能用。

add_filter( 'display_post_states', 'ecs_add_post_state', 10, 2 );
function ecs_add_post_state( $post_states, $post ) {
    if( $post->post_name == 'edit-profile' ) {
        $post_states[] = 'Profile edit page';
    }
    return $post_states;
}

类是“后状态”。我想知道如何根据帖子 ID 或页面标题以外的其他内容将此文本添加到页面,因为我的某些页面没有标题,因此显示“(无标题)”。

此文本的一个示例是 WordPress“主页 - 头版”或“- 隐私政策页面”。下面的代码是主页行的管理面板中的 html。接下来的文本:“- Front Page”,这是我希望添加的,位于下面代码末尾的 span 标记内。

<tr id="post-2" class="iedit author-self level-0 post-2 type-page status-publish hentry">
            <th scope="row" class="check-column">           <label class="screen-reader-text" for="cb-select-2">
                                                                                Select Home         </label>
            <input id="cb-select-2" type="checkbox" name="post[]" value="2">
            <div class="locked-indicator">
                <span class="locked-indicator-icon" aria-hidden="true"></span>
                <span class="screen-reader-text">
                “Home” is locked                </span>
            </div>
            </th><td class="title column-title has-row-actions column-primary page-title" data-colname="Title"><div class="locked-info"><span class="locked-avatar"></span> <span class="locked-text"></span></div>
<strong><a class="row-title" href="https://test.winningsportsplays.com/wp-admin/post.php?post=2&amp;action=edit" aria-label="“Home” (Edit)">Home</a> — <span class="post-state">Front Page</span></strong>

【问题讨论】:

  • $post 中的 ecs_add_post_state 对象包含您可以像这样访问的帖子的 ID:$post-&gt;ID。因此,将if( $post-&gt;post_name == 'edit-profile' ) { 更改为if( $post-&gt;ID == YOUR-ID-HERE ) { 将让您在给定的帖子ID 匹配条件时执行您需要执行的任何操作。你试过了吗?
  • @cabrerahector 我离得很近。惊人的!谢谢!我希望这对将来的某人有所帮助。
  • 随意回答您自己的问题并在此处包含您的解决方案,也许有人会从阅读您的代码中受益:)

标签: php jquery wordpress


【解决方案1】:

@cabrerahector 谢谢!

add_filter( 'display_post_states', 'ecs_add_post_state', 10, 2 );
function ecs_add_post_state( $post_states, $post ) {
    if( $post->ID == YOUR-ID-HERE ) {
        $post_states[] = 'Profile edit page';
    }
    return $post_states;
}

【讨论】:

    猜你喜欢
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2015-02-05
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多