Using WordPress ‘get_sample_permalink_html()’ PHP function

The get_sample_permalink_html() WordPress PHP function returns the HTML of the sample permalink slug editor.

Usage

get_sample_permalink_html( $post, $new_title, $new_slug );

Parameters

  • $post (int|WP_Post) – Required. Post ID or post object.
  • $new_title (string|null) – Optional. New title. Default: null.
  • $new_slug (string|null) – Optional. New slug. Default: null.

More information

See WordPress Developer Resources: get_sample_permalink_html()

Note: This filter no longer works if Gutenberg is enabled on your PostType.

Examples

Display the sample permalink HTML for a specific post

This example displays the sample permalink HTML for a post with the ID of 1.

$post_id = 1;
$permalink_html = get_sample_permalink_html( $post_id );
echo $permalink_html;

Update the title and slug for a specific post

This example updates the title and slug for a post with the ID of 2.

$post_id = 2;
$new_title = 'Updated Title';
$new_slug = 'updated-title';
$permalink_html = get_sample_permalink_html( $post_id, $new_title, $new_slug );
echo $permalink_html;

Update the title only for a specific post

This example updates the title for a post with the ID of 3.

$post_id = 3;
$new_title = 'Updated Title Only';
$permalink_html = get_sample_permalink_html( $post_id, $new_title );
echo $permalink_html;

Update the slug only for a specific post

This example updates the slug for a post with the ID of 4.

$post_id = 4;
$new_slug = 'updated-slug-only';
$permalink_html = get_sample_permalink_html( $post_id, null, $new_slug );
echo $permalink_html;

Display the sample permalink HTML for a WP_Post object

This example displays the sample permalink HTML for a WP_Post object.

$post = get_post( 5 );
$permalink_html = get_sample_permalink_html( $post );
echo $permalink_html;