Skip to content

Instantly share code, notes, and snippets.

@aahan
Last active December 25, 2015 22:49
Show Gist options
  • Select an option

  • Save aahan/7052592 to your computer and use it in GitHub Desktop.

Select an option

Save aahan/7052592 to your computer and use it in GitHub Desktop.
<?php
/*
* How to use `get_post_type_object` function
* http://wordpress.stackexchange.com/q/6731
*/
if( !in_array( $post->post_type, array( 'post', 'page' ) ) ) {
// if( 'post' != get_post_type() || 'page' != get_post_type() ) {
$pt_obj = get_post_type_object( $post->post_type );
$pt_link = get_post_type_archive_link( $post->post_type );
// http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
echo '<a href="' . $pt_link . '">' . $pt_obj->label . '</a>';
// echo '<a href="' . $pt_link . '">' . $pt_obj->labels->singular_name . '</a>';
// echo '<a href="' . $pt_link . '">' . $pt_obj->labels->archive_title . '</a>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment