Filter hook 'wp_unique_post_slug_is_bad_attachment_slug'

in WP Core File wp-includes/post.php at line 5427

View Source

wp_unique_post_slug_is_bad_attachment_slug

Filter Hook
Description
Filters whether the post slug would make a bad attachment slug.

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Filter
Line Number 5427

Hook Parameters

Type Name Description
bool $bad_slug Whether the slug would be bad as an attachment slug.
string $slug The post slug.

Usage Examples

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

function my_custom_filter($bad_slug, $slug) {
    // Your custom filtering logic here
    return $bad_slug;
}

Source Code Context

wp-includes/post.php:5427 - How this hook is used in WordPress core
<?php
5422  		 * @since 3.1.0
5423  		 *
5424  		 * @param bool   $bad_slug Whether the slug would be bad as an attachment slug.
5425  		 * @param string $slug     The post slug.
5426  		 */
5427  		$is_bad_attachment_slug = apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug );
5428  
5429  		if ( $post_name_check
5430  			|| in_array( $slug, $feeds, true ) || 'embed' === $slug
5431  			|| $is_bad_attachment_slug
5432  		) {

PHP Documentation

<?php
/**
		 * Filters whether the post slug would make a bad attachment slug.
		 *
		 * @since 3.1.0
		 *
		 * @param bool   $bad_slug Whether the slug would be bad as an attachment slug.
		 * @param string $slug     The post slug.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.