I tried to find filters or a hook to modify link returned by this function


I have gone through most of the documentation. I'm not sure it's not there or I'm not able to find it.

Any suggestions would be very appreciated.

3 Answers 3


The filter is post_type_archive_link, defined (WP 4.1.1) on line 1112 of file wp-includes/link-template.php:

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

And the use:

add_filter( 'post_type_archive_link', function( $link, $post_type ) {

    //Do something

    return $link;

}, 10, 2 );

Just look at the source of get_post_type_archive_link():

return apply_filters( 'post_type_archive_link', $link, $post_type );

Sidenote: The function uses home_url(), which is a wrapper for get_home_url(), which offers another filter:

return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );

that runs earlier. With "pretty permalinks" enabled, it runs the following:

$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );

and without:

$link = home_url( '?post_type=' . $post_type );

Welcome to WPSE Ittikorn!

Sometimes it is the easiest to just look right at the source. There even is a link right at the bottom of the Codex page you linked:


There you can easily see that there actually is a filter called post_type_archive_link

So to give you an example:

add_filter( "post_type_archive_link", "wpse_179209", 10, 2 );

function wpse_179209( $link, $post_type ){
    // Do whatever you want to the $link

    return $link;

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.