blog posts

Setting up unique links in WordPress and removing WordPress unique link restrictions

Setting the unique link in WordPress and removing the limitation of the unique link in WordPress is one of the problems that occur mostly for Persian-speaking users, because in languages ​​like Farsi and Arabic, the URL is read as ISO, which in the end links your posts in the form of characters that consist of Numbers, Latin letters and % character will be converted. In fact, the address of one of your posts will be completely strange. But in the meantime, the problem that exists is that when you choose a title such as “setting a unique link in WordPress and removing the limitation of a unique WordPress link” for your post, if your unique link is set on the name of the post, the link of the post is incomplete and It may take the form of “setting-unique-link-WordPress-fix-restriction” that no matter how many times you click on the edit button in front of the single link to complete it, the changes will not be applied.

In this article from Hostfa’s knowledge base, I intend to examine the problem of the limitation of unique links in WordPress and finally use the existing solutions to make sure that our unique links are fully inserted. So stay with us until the end.

Setting up unique links in WordPress and removing WordPress unique link restrictions

Before introducing the solutions, I need to mention some very important things so that you can make your decision to change the unique link structure and remove the limit on the number of characters in WordPress. Maybe you are faced with this issue for the first time and you see that your unique link is registered half and half. You think that it is a problem with WordPress or, like many others, you say that WordPress has a bug, but this is not the case at all. The reason why WordPress has applied this limit to unique links is nothing but following SEO tips and website optimization in the eyes of search engines like Google.

By default, WordPress has set the number of characters allowed to be in a single link to 70. Because in terms of SEO and website optimization, search engines do not read more than this amount. So if you have a long unique link, only the first 70 characters will be read and the rest will be ignored, now also consider that the most important words that are keywords are in the second half, which the search engine will not read. In this case, your chances of being placed in higher results will be lower.

Another problem with using a long single link is related to the website itself. That is, when you have long unique links, you will face the following errors.

  • Continuous site timeout
  • Encountering 404 errors
So, now that you are familiar with the problems of this limitation and you have made your decision to remove the limitation or not to remove the limitation of the number of characters in the unique WordPress link, you can now remove the limitation of the number of characters in the unique WordPress link using the following methods.

A plugin to remove the limit of the number of characters of a unique WordPress link

As always, the first and easiest solution will be to use the plugin. The plugin that I am going to introduce, called Longer Permalinks, has been registered in the WordPress repository and has been able to achieve more than 100 active installations and get 5 points from it. increase

After installing and activating this plugin, you don’t need to do anything else, just install and activate it to start working, the plugin doesn’t have any settings, and after installing it, the menu will not be added to your WordPress dashboard. From now on, any title you have entered for your article will be included in full in the unique link of the article. Note that this plugin will allow you to use up to 300 characters in the text. Therefore, to maintain the SEO of the site and not harm your site, try to remove these problems by editing the unique link.

Fixing the limit of the number of characters of a unique WordPress link from the functions.php file

If you don’t want to use the plugin, you can use the Functions.php file of the template to remove the limit of the number of characters of a unique link in WordPress. Go to your template editor and then look for a file called functions.php. by clicking on File Manager /public_html/wp-content/themes/ .

Setting up unique links in WordPress and removing WordPress unique link restrictions

Then enter the folder of the template you are currently using and find the desired file for editing. After finding the file, if . you are using cPanel host, just right click on the desired file and select Edit option Now that the editor page is opened, put the following codes in the appropriate place of this file. I suggest you put these codes at the end of the file.

Make sure that you have a copy of the function file (functions.php) before any changes, so that if you put the code in the wrong place and the site encounters an error, replace the code immediately to solve the problem.
add_filter( 'sanitize_title', 'wpse52690_limit_length', 1, 3 );

function wpse52690_limit_length( $title, $raw_title, $context ) {
    //  filters
    if( $context != 'save' )
        return $title;

    //  vars
    $desired_length = 20; //number of chars
    $desired_words = 5; //number of words
    $prohibited = array(
        'the'
        ,'in'
        ,'my'
        ,'etc'
        //put any more words you do not want to be in the slug in this array
    );

    //  do the actual work
    // filter out unwanted words
    $_title = explode( ' ', $title );
    //if you want more than one switch to preg_split()
    $_title = array_diff( $_title, $prohibited );
    // count letters and recombine
    $new_title = '';
    for( $i=0, $count=count($_title); $i<$count; $i++ ) {
        //check for number of words
        if( $i > $desired_words )
            break;
        //check for number of letters
        if( mb_strlen( $new_title.' '.$_title[$i] ) > $desired_length )
            break;

        if( $i != 0 )
            $new_title .= ' ';
        $new_title .= $_title[$i];
    }

    return $new_title;
} 

Now, after saving the file, you will be able to fully use the title you entered for the article in the unique link of your article.