When we use WordPress, we usually like to use the article alias as a fixed link. This alias is also the slug name. When we edit the article, we can customize the article alias. Of course, we can also click "Quick Edit" under an article on the article editing page, and we can also edit the alias here.
But WordPress does not provide a method to obtain this alias. WordPress provides the_title() to get the article title, and the_permalink() to get the link of the current article, but there is no function to get the article alias.
We can add a function in functions.php in the theme directory, the code is as follows:
function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; }
In this way, we can call the function where we need it, such as the following calling method:
<?php echo the_slug(); ?>
The above introduces Xin Xing’s brief analysis of aliases in WordPress, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.