Skip to content

Instantly share code, notes, and snippets.

@shizhua
Created March 8, 2016 02:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shizhua/c5cae9e457574d794bc3 to your computer and use it in GitHub Desktop.
Save shizhua/c5cae9e457574d794bc3 to your computer and use it in GitHub Desktop.
Add custom post states in WordPress
<?php
add_filter('display_post_states', 'wpsites_custom_post_states');
function wpsites_custom_post_states($states) {
global $post;
if( ('page'==get_post_type($post->ID)) && ('page-templates/custom-page-template.php'==get_page_template_slug($post->ID)) ) {
$states[] = __('Custom state');
}
}
@harkor
Copy link

harkor commented Apr 6, 2021

Hi,

Thanks for snippet.

you forgot "return $states;" at the end.

<?php
add_filter('display_post_states', 'wpsites_custom_post_states');

function wpsites_custom_post_states($states) {
    global $post;
    if( ('page'==get_post_type($post->ID)) && ('page-templates/custom-page-template.php'==get_page_template_slug($post->ID)) ) {
        $states[] = __('Custom state');
    }

    return $states;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment