Filter hook 'post_type_link'

in WP Core File wp-includes/link-template.php at line 375

View Source

post_type_link

Filter Hook
Description
Filters the permalink for a post of a custom post type.

Hook Information

File Location wp-includes/link-template.php View on GitHub
Hook Type Filter
Line Number 375

Hook Parameters

Type Name Description
string $post_link The post's permalink.
WP_Post $post The post in question.
bool $leavename Whether to keep the post name.
bool $sample Is it a sample permalink.

Usage Examples

Basic Usage
<?php
// Hook into post_type_link
add_filter('post_type_link', 'my_custom_filter', 10, 4);

function my_custom_filter($post_link, $post, $leavename, $sample) {
    // Your custom filtering logic here
    return $post_link;
}

Source Code Context

wp-includes/link-template.php:375 - How this hook is used in WordPress core
<?php
 370  	 * @param string  $post_link The post's permalink.
 371  	 * @param WP_Post $post      The post in question.
 372  	 * @param bool    $leavename Whether to keep the post name.
 373  	 * @param bool    $sample    Is it a sample permalink.
 374  	 */
 375  	return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample );
 376  }
 377  
 378  /**
 379   * Retrieves the permalink for the current page or page ID.
 380   *

PHP Documentation

<?php
/**
	 * Filters the permalink for a post of a custom post type.
	 *
	 * @since 3.0.0
	 *
	 * @param string  $post_link The post's permalink.
	 * @param WP_Post $post      The post in question.
	 * @param bool    $leavename Whether to keep the post name.
	 * @param bool    $sample    Is it a sample permalink.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/link-template.php
Related Hooks

Related hooks will be displayed here in future updates.