0

I want to be able to easily create/edit my own custom "post-state" for display in the Pages back end.

I only want this text appearing after the page name - not in the status dropdown, or anywhere else.

WooCommerce, Elementor & a whole host of other plugins do this for their own internally created pages, to the point where they even concatenate if there is an pre-existing state eg:
post-state example
However, I cannot seem to find anywhere that I can just easily edit this text, or add my own.

This question was the only one I could find that asks about post-state and the provided answers, while they might work, rely on my editing functions.php and dealing with code every time I want to add/change the text or even if the page id changes.

I would prefer something more simple: an "edit post state" button for each page in the list that just brings a text box that I can input new or change existing text for any page I want.

Unsuccessful so far in searching the plugins at wordpress.org (only results are for highlighting WP built-in states such as 'draft', adding in preset states such as 'archive', or creating entire new Post Status that appears in the dropdown & other places.)

If there is another type of plugin/code that can provide the same functionality, that would also be acceptable - basically I want to be able to just add a short admin-only description for the sake of differentiating between nondescript page names*, without having to change the actual page name itself.

*such as when I am experimenting with a few different plugins that generate the same page names eg. My Account, or if I want a sandbox page but still have it called the same name as my proper page.

  • One of my biggest issues when searching for a resolution to this question was finding out what that grey text is actually referred to!! I had to resort to looking at source code for a clue in the html & it is called post-state in there, also when attempting to tag I did not see the post-status tag that @fuxia just added for me - thanks, this might speed up discovering a good solution. – RozzA Nov 3 '18 at 1:37
  • Upon further delving there appears to be a plugin called Edit Flow but that seems like a lot of bulk just to do this one small thing – RozzA Nov 3 '18 at 3:18
0

_post_states( WP_Post $post )

Parameters #Parameters

$post (WP_Post) (Required)

Code Reference from wordpress.org (https://developer.wordpress.org/reference/functions/_post_states/)

function _post_states($post) {
$post_states = array();
if ( isset( $_REQUEST['post_status'] ) )
    $post_status = $_REQUEST['post_status'];
else
    $post_status = '';

if ( !empty($post->post_password) )
    $post_states['protected'] = __('Password protected');
if ( 'private' == $post->post_status && 'private' != $post_status )
    $post_states['private'] = __('Private');
if ( 'draft' === $post->post_status ) {
    if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
        $post_states[] = __( 'Customization Draft' );
    } elseif ( 'draft' !== $post_status ) {
        $post_states['draft'] = __( 'Draft' );
    }
} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
    $post_states[] = __( 'Customization Draft' );
}
if ( 'pending' == $post->post_status && 'pending' != $post_status )
    $post_states['pending'] = _x('Pending', 'post status');
if ( is_sticky($post->ID) )
    $post_states['sticky'] = __('Sticky');

if ( 'future' === $post->post_status ) {
    $post_states['scheduled'] = __( 'Scheduled' );
}

if ( 'page' === get_option( 'show_on_front' ) ) {
    if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
        $post_states['page_on_front'] = __( 'Front Page' );
    }

    if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
        $post_states['page_for_posts'] = __( 'Posts Page' );
    }
}

if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
    $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' );
}

/**
 * Filters the default post display states used in the posts list table.
 *
 * @since 2.8.0
 * @since 3.6.0 Added the `$post` parameter.
 *
 * @param array   $post_states An array of post display states.
 * @param WP_Post $post        The current post object.
 */
$post_states = apply_filters( 'display_post_states', $post_states, $post );

if ( ! empty($post_states) ) {
    $state_count = count($post_states);
    $i = 0;
    echo ' — ';
    foreach ( $post_states as $state ) {
        ++$i;
        ( $i == $state_count ) ? $sep = '' : $sep = ', ';
        echo "<span class='post-state'>$state$sep</span>";
    }
}

enter image description here

For Example: This Code from Ultimate Member plugin

/**
     * Add a post display state for special UM pages in the page list table.
     *
     * @param array $post_states An array of post display states.
     * @param \WP_Post $post The current post object.
     *
     * @return mixed
     */
    public function add_display_post_states( $post_states, $post ) {

        foreach ( UM()->config()->core_pages as $page_key => $page_value ) {
            $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) );

            if ( $page_id == $post->ID ) {
                $post_states[ 'um_core_page_' . $page_key ] = sprintf( 'UM %s', $page_value['title'] );
            }
        }

        return $post_states;
    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.