Wenprise Pinyin Slug: Convert file name, website address to pinyin or English

Wenprise Pinyin Slug automatically converts Chinese article aliases, category item aliases, and image file names in WordPress to Pinyin or English.

Websites created for customers generally need to be considered comprehensively. One of them is the treatment of Chinese in link URLs. Chinese is usually displayed as garbled in URLs, and attachments are stored in the server with Chinese names. During the process of changing the host, file names may be garbled and file URLs become invalid. These problems have been encountered. Previously, Meng recommended plug-ins:

WordPress automatically converts Chinese links to pinyin SO Pinyin Slugs 

SO Pinyin Slugs is still very easy to use, but it does not support conversion of attachment file names to pinyin. I recommend Wenprise Pinyin Slug today. One plug-in contains the above two functions!

Wenprise Pinyin Slug automatically converts Chinese article aliases, category item aliases, and image file names in WordPress to Pinyin or English (using Baidu Translation API).

Wenprise Pinyin Slug: Convert file name, website address to pinyin or English
Wenprise Pinyin Slug: Convert file name, website address to pinyin or English
Wenprise Pinyin Slug: Convert file name, website address to pinyin or English
Wenprise Pinyin Slug: Convert file name, website address to pinyin or English

article directories

Main functions of the plug-in

  • Convert article aliases to Pinyin or English, and support conversion during quick editing
  • Convert categories, tags, or custom classification aliases to Pinyin, supporting conversion during quick editing
  • When the alias is in English, or when a Chinese alias is set manually, it remains as it is
  • Convert Chinese picture names to pinyin
  • Support custom conversion methods to full spelling or first letter
  • Support setting of spacing characters between Pinyin
  • Support interception of converted pinyin to the set length
  • Support Gutenberg Editor

Why do you need this plug-in?

When Chinese appears in the URL, the Chinese part will be automatically transcoded. Those who don’t know will look like a mess of garbled code and lack readability. Although some browsers can display Chinese in the address bar, when copying and sharing it to others, the Chinese part of the URL also displays the transcoded code.

Different operating system environments use different file name encodings. When migrating the server, if the file name encoding changes, the Chinese file name may become garbled, making the file inaccessible.

When to use this plug-in?

If your site is for customers, use this plug-in is recommended because they will likely not be aware of the problem of using Chinese in URLs and file names. This plug-in can automatically help them handle it.

If you use the site yourself and you are a careful person who manually edits aliases and file names when publishing content, this plug-in is unnecessary for you. No installation is required.

Plug-in download and install

You can search Wenprise Pinyin Slug in the background plug-in installation interface to install, or go to the official download wordpress.org/plugins/wenprise-pinyin-slug/ and upload and install.

Add a time stamp to the file name

In order to avoid performance problems caused by users uploading too many files with the same name, and to avoid others guessing the file name of some files, we can consider adding a timestamp to the file name.

Timestamp only the converted file name

if you wantTimestamps only Wenprise Pinyin Slug converted file names, you can use the following code. Add it to the theme’s functions.php or other plug-in file:

/**
 * The replacement file name is Pinyin + Timestamp
 * https://www.wpdaxue.com/wenprise-pinyin-slug.html
 * @param $slug
 * @param $name
 * @param $type
 *
 * @return string After conversion, pinyin + timestamp
 */
add_filter('wenprise_converted_slug', function ( $slug, $name, $type )
{

    if( $type == 'file' ) {
        $slug = $slug. '-'.time();
    }

    return $slug;

}, 99, 3);

Note: Only Wenprise Pinyin Slug is the only method above 1.5.2 The above version will only take effect!

forallAdd time stamp to file name

if you wantTimestamp all file names, compatible at the same time Wenprise Pinyin Slug For the conversion function of, you can use the following code. Add it to the theme’s functions.php or other plug-in file:

/ * *
* for all file names + timestamps
* https://www.wpdaxue.com/wenprise-pinyin-slug.html
* @ param $filename
*
* @ return mixed
, /
Add_filter ('sanitize_file_name', function ($filename))
{

$disable_file_convert = wprs_slug_get_option ('wprs_pinyin_slug',' disable_file_convert', 'off')

If ($disable_file_convert = = 'on') {
Return $filename
}

/ / do not automatically convert to Pinyin when editing manually
$parts = explode ('.', $filename)

/ / if there is no suffix, return the file name directly without adding it. And suffix
If (count ($parts) & lt;= 1) {
If (preg_match ('/ [\ x {4e00} -\ x {9fa5}] + / 9fa5, $filename)) {
Return wprs_slug_convert ($filename, 'file')
}

Return $filename
}

$filename = array_shift ($parts)
$extension = array_pop ($parts)

Foreach ((array) $parts as $part) {
$filename. ='. $part
}

If (preg_match ('/ [\ x {4e00} -\ x {9fa5}] + / 9fa5, $filename)) {
$filename = wprs_slug_convert ($filename, 'file')
}

$filename. ='- '.time ()

$filename. ='. $extension

Return $filename


}, 99,1)

Note: You can choose one of the above two codes according to your actual needs, and do not use both.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注