WordPress filter hook · part of WordPress core
post_link
A WordPress core filter that 6 plugins also fire themselves, running on 137K+ sites between them.
“Filters the permalink for a post. Only applies to posts with post_type of 'post'.”
How to use post_link
It's a filter: your callback receives the value and 2 more arguments, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'post_link', function( $permalink, $post, $leavename ) {
// Change $permalink here.
return $permalink;
}, 10, 3 );Argument names come from Hubbub Lite's source. Other plugins may pass different values: check the call in the plugin you're targeting below.
This hook is fired by WordPress core too. Official reference on developer.wordpress.org →
6 plugins that fire post_link
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Nested Pages90,000+ installs
apply_filters( 'post_link', $link, $this->post, false )app/Views/partials/row.php:259 -
Hubbub Lite30,000+ installs
apply_filters( 'post_link', $permalink, $post, $leavename )inc/functions-post.php:490 -
Social Sharing Plugin10,000+ installs
apply_filters( 'post_link', $permalink, $post, $leavename )lib/url-management/SWP_Permalink.php:172 -
Posts List7,000+ installs
apply_filters( 'post_link', $permalink, $post, $leavename )posts-list.php:356 -
Ultimate Social Media Share20+ installs
apply_filters( 'post_link', $permalink, $post, false )inc/share_counts_recovery.php:300 -
BuddyPress Backwards Compatibility10+ installs
apply_filters( 'post_link', $permalink, $post )bp-blogs/bp-blogs-templatetags.php:420
Need a customisation built on this hook?
Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.