Home  >  Article  >  Backend Development  >  Xin Xing briefly analyzes aliases in WordPress

Xin Xing briefly analyzes aliases in WordPress

WBOY
WBOYOriginal
2016-08-08 09:24:18964browse

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(); ?>
If our alias is in Chinese, then the encoded text will be called, but we generally use English, which is more convenient for SEO.
Reference: http://www.insitewebsitedesign.com/wordpress-post-slug-and-page-slug-function



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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn