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

How to use post_type_archive_link filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 8, 2023
5 minutes read

post_type_archive_link filter

Filters the post type archive permalink.

apply_filters( 'post_type_archive_link', string $link, string $post_type )

Description

This is filter hook , its filter the post type archive permalink.
Its consists of two parameters, one is $link, second is $post_type .

It is used in get_post_type_archive_link() which retrieves the permalink for a post type archive.

Parameters

  • $link : (string) The post type archive permalink.
  • $post_type : (string) Post type name.

Live Example

To run the hook, copy the example below.

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

The following example is for adding a hook callback.

// define the post_type_archive_link callback 
function filter_post_type_archive_link( $link, $post_type ) { 
    // make filter magic happen here... 
    return $link; 
}; 
         
// add the filter 
add_filter( 'post_type_archive_link', 'filter_post_type_archive_link', 10, 2 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_type_archive_link', 'filter_post_type_archive_link', 10, 2 ); 

 

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.