PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Pathauto added special characters in url alias - drupal 7

27 Jul 2016

Pathauto added special characters in url alias - drupal 7

    To improve SEO, we need to clean our URLs. By default in drupal, we've an option called clean URLs at the configuration. In drupal 7, we can also manage the URLs. For instance, you have a content type called services. You wanted to each service page have url like services/page-name. To do that, we've a pathauto module in drupal 7. The pathauto module allow us to manage the URLs for every content types, files, taxonomy & users and also we can remove some unnecessary words from URL like an, the and so on.

   The pathauto module can remove some unnecessary words like a, an, the and so on & also remove special characters like !, @, $ and so on. Unfortunately, it doesn't included some other symbols like copyright(©), trademark(™), registered(®) and so on. But it provide a hook to add new symbols into the punctuation settings called hook_pathauto_punctuation_chars_alter. After created a content with some symbols which are represented above, your page URL looks like below image:


Drupal 7 - remove special characters from url using pathauto module



/**
 * Implements hook_pathauto_punctuation_chars_alter().
 */
function phponwebsites_pathauto_punctuation_chars_alter(array &$punctuation) {
  $punctuation['copyright']          = array('value' => '©', 'name' => t('Copyright'));
  $punctuation['registered']         = array('value' => '®', 'name' => t('Registered trademark'));
  $punctuation['trademark']          = array('value' => '™', 'name' => t('Trademark'));
}

   After implemented above code into your module, you cold see added symbols are listing on Pathauto module's settings page at /admin/config/search/path/settings. If You didn't get these symbols, clear cache & test it again. It looks like below image:


Drupal 7 - pathauto settings after hook_pathauto_punctuation_chars_alter


Now you can create a content with those symbols. The pathauto module didn't added those symbols into the URL.

Now I hope you know how to remove some special characters from URL alias using pathauto module in drupal 7.

17 comments:

  1. An alternative solution would be to use the Transliteration module (https://www.drupal.org/project/transliteration)

    ReplyDelete
  2. We understand that with the described methods for 192.168.0.1 configuration is usually a bit complicated for people. In the event you have some complications signing in just contact the support team of the router company. We're the group if technology experts who are providing the solutions for 192.168.0.l set up as well as 192.168.0.1 Administrative connection for a long time.

    ReplyDelete
  3. This is such a great resource that me are providing and you give it away for free.
    seeing that understand the value of providing a quality resource for free. :) :)
    bloons tower defense 5
    super smash flash 2

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. The article you have shared here very good. This is really interesting information for me. Thanks for sharing!
    - www.hotmail.com
    - google mail

    ReplyDelete
  6. DISCUSSION PAPER casesolution
    No doubt! It will be truly hard enrolling! I wish you good fortunes!

    ReplyDelete
  7. E Tuition Pakistan
    This a good way to appreciate the teacher as they put their efforts to train students. UK dissertation Writers appreciates the teachers.

    ReplyDelete
  8. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    animal jam | five nights at freddy's | hotmail login

    ReplyDelete