Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_type_labels_post_type filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 8, 2022
5 minutes read
Share Via:

post_type_labels_post_type filter

The dynamic portion of the hook name, $post_type, refers to the post type slug.

apply_filters( "post_type_labels_{$post_type}", object $labels )

Description

This is filter hook , its filter the labels of a specific post type.
Its includes the following hook names include:

post_type_labels_post
post_type_labels_page
post_type_labels_attachment

Parameters

  • $labels : (object) Object with labels for the post type as member variables.

Live Example

To run the hook, copy the example below.

$labels = apply_filters( 'post_type_labels_{$post_type}', $labels ); 
                         
if ( !empty( $labels ) ) { 
                         
   // everything has led up to this point... 
                         
} 
  

The following example is for adding a hook callback.

// define the post_type_labels_<post_type> callback 
function filter_post_type_labels_post_type( $labels ) { 
    // make filter magic happen here... 
    return $labels; 
}; 
         
// add the filter 
add_filter( "post_type_labels_{$post_type}", 'filter_post_type_labels_post_type', 10, 1 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( "post_type_labels_{$post_type}", 'filter_post_type_labels_post_type', 10, 1 ); 

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.