WordPress filter hook · part of WordPress core

pre_post_link

A WordPress core filter that 5 plugins also fire themselves, running on 47K+ sites between them.

“Filters the permalink structure for a post before token replacement occurs. Only applies to posts with post_type of 'post'.”

How to use pre_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:

functions.php
add_filter( 'pre_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 →

5 plugins that fire pre_post_link

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Hubbub Lite icon Hubbub Lite30,000+ installs apply_filters( 'pre_post_link', $permalink, $post, $leavename ) inc/functions-post.php:403
  2. Social Sharing Plugin icon Social Sharing Plugin10,000+ installs apply_filters( 'pre_post_link', $permalink, $post, $leavename ) lib/url-management/SWP_Permalink.php:87
  3. Posts List icon Posts List7,000+ installs apply_filters( 'pre_post_link', $permalink, $post, $leavename ) posts-list.php:308
  4. WP Permastructure icon WP Permastructure400+ installs apply_filters( 'pre_post_link', $permalink, $post, $leavename ) wp-permastructure.php:304
  5. Ultimate Social Media Share icon Ultimate Social Media Share20+ installs apply_filters( 'pre_post_link', $permalink_structure, $post, false ) inc/share_counts_recovery.php:212

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.