Title: wp_force_plain_post_permalink
Published: March 9, 2021
Last modified: February 24, 2026

---

# wp_force_plain_post_permalink( WP_Post|int|null $post = null, bool|null $sample = null ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#wp--skip-link--target)

Determine whether post should always use a plain permalink structure.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#parameters)󠁿

 `$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|int
|nulloptional

Post ID or post object. Defaults to global $post.

Default:`null`

`$sample`bool|nulloptional

Whether to force consideration based on sample links.
 If omitted, a sample link
is generated if a post object is passed with the filter property set to `'sample'`.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#return)󠁿

 bool Whether to use a plain permalink structure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#source)󠁿

    ```php
    function wp_force_plain_post_permalink( $post = null, $sample = null ) {
    	if (
    		null === $sample &&
    		is_object( $post ) &&
    		isset( $post->filter ) &&
    		'sample' === $post->filter
    	) {
    		$sample = true;
    	} else {
    		$post   = get_post( $post );
    		$sample = null !== $sample ? $sample : false;
    	}

    	if ( ! $post ) {
    		return true;
    	}

    	$post_status_obj = get_post_status_object( get_post_status( $post ) );
    	$post_type_obj   = get_post_type_object( get_post_type( $post ) );

    	if ( ! $post_status_obj || ! $post_type_obj ) {
    		return true;
    	}

    	if (
    		// Publicly viewable links never have plain permalinks.
    		is_post_status_viewable( $post_status_obj ) ||
    		(
    			// Private posts don't have plain permalinks if the user can read them.
    			$post_status_obj->private &&
    			current_user_can( 'read_post', $post->ID )
    		) ||
    		// Protected posts don't have plain links if getting a sample URL.
    		( $post_status_obj->protected && $sample )
    	) {
    		return false;
    	}

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/link-template.php#L103)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/link-template.php#L103-L142)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#related)󠁿

| Uses | Description | 
| [is_post_status_viewable()](https://developer.wordpress.org/reference/functions/is_post_status_viewable/)`wp-includes/post.php` |

Determines whether a post status is considered “viewable”.

  | 
| [get_post_status_object()](https://developer.wordpress.org/reference/functions/get_post_status_object/)`wp-includes/post.php` |

Retrieves a post status object by name.

  | 
| [get_post_status()](https://developer.wordpress.org/reference/functions/get_post_status/)`wp-includes/post.php` |

Retrieves the post status based on the post ID.

  | 
| [get_post_type()](https://developer.wordpress.org/reference/functions/get_post_type/)`wp-includes/post.php` |

Retrieves the post type of the current post or of a given post.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [get_post_type_object()](https://developer.wordpress.org/reference/functions/get_post_type_object/)`wp-includes/post.php` |

Retrieves a post type object by name.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#)

| Used by | Description | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [get_post_permalink()](https://developer.wordpress.org/reference/functions/get_post_permalink/)`wp-includes/link-template.php` |

Retrieves the permalink for a post of a custom post type.

  | 
| [_get_page_link()](https://developer.wordpress.org/reference/functions/_get_page_link/)`wp-includes/link-template.php` |

Retrieves the page permalink.

  | 
| [get_attachment_link()](https://developer.wordpress.org/reference/functions/get_attachment_link/)`wp-includes/link-template.php` |

Retrieves the permalink for an attachment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/?output_format=md#comment-content-6770)
 2.   [Rodrigo Vieira Eufrasio da Silva](https://profiles.wordpress.org/rodrigomct/)
    [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/#comment-6770)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_force_plain_post_permalink%2F%23comment-6770)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_force_plain_post_permalink%2F%23comment-6770)
 4.     ```php
        // Get the current post
        $current_post = get_post();
    
        // Checks if the post should use a simple permalink structure
        $force_plain_permalink = wp_force_plain_post_permalink( $current_post );
    
        // Use the result to customize the permalink output
        if ( $force_plain_permalink ) {
            echo trailingslashit( esc_url( get_permalink( $current_post ) ) ); // Add a slash at the end for a simple permalink structure
        } else {
            echo esc_url( get_permalink( $current_post ) ); // Uses the standard permalink structure
        }
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_force_plain_post_permalink%2F%3Freplytocom%3D6770%23feedback-editor-6770)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_force_plain_post_permalink%2F)
before being able to contribute a note or feedback.