The post_slug_meta_box WordPress PHP function displays slug form fields for a given post.
Usage
post_slug_meta_box( $post );
Custom example:
$post = get_post( 12 ); // Get post with ID 12 post_slug_meta_box( $post ); // Display the slug form field for the post with ID 12
Parameters
$post
(WP_Post) – Required. The current post object.
More information
See WordPress Developer Resources: post_slug_meta_box
Examples
Display slug form field for the current post
This example will display the slug form field for the current post in the loop.
global $post; post_slug_meta_box( $post ); // Display the slug form field for the current post
Display slug form field for a post by ID
This example will display the slug form field for a post with a specific ID.
$post_id = 42; $post = get_post( $post_id ); post_slug_meta_box( $post ); // Display the slug form field for the post with ID 42
Display slug form field for a post by title
This example will display the slug form field for a post with a specific title.
$post_title = 'Hello World'; $post = get_page_by_title( $post_title, OBJECT, 'post' ); post_slug_meta_box( $post ); // Display the slug form field for the post titled 'Hello World'
Display slug form field for the latest post
This example will display the slug form field for the latest published post.
$args = array( 'numberposts' => 1, 'post_status' => 'publish', ); $latest_post = wp_get_recent_posts( $args, OBJECT )[0]; post_slug_meta_box( $latest_post ); // Display the slug form field for the latest published post
Display slug form field for a random post
This example will display the slug form field for a random published post.
$args = array( 'numberposts' => 1, 'orderby' => 'rand', 'post_status' => 'publish', ); $random_post = wp_get_recent_posts( $args, OBJECT )[0]; post_slug_meta_box( $random_post ); // Display the slug form field for a random published post