Optimizing URLs in WordPress
I'm thinking about what to include CNC many of the readers on the site know and can skip the next comment. For those who don't know, here's an example..
1 2 3 4 5 |
// Текст без ЧПУ /articles.php?id=148 // Текст с ЧПУ /text-about-wordpress |
In WordPress CNC included in Settings -> Permalink Settings. The best option is when the link is as short as possible by nesting, and by the length of the link text, therefore, you must select the Custom Structure item and enter /% postname% /.
Climbing once again on the baynet, I found the code, which makes URL even shorter. Code removes from URL short words with a given number of characters.
Link optimization code example:
1 2 3 4 5 6 7 8 9 10 11 |
add_filter('sanitize_title', 'remove_short_words'); function remove_short_words($slug) { if (!is_admin()) return $slug; $slug = explode('-', $slug); foreach ($slug as $k => $word) { if (strlen($word) < 3) { unset($slug[$k]); } } return implode('-', $slug); } |
You can also remove individual stop words from the page address:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
add_filter('sanitize_title', 'remove_false_words'); function remove_false_words($slug) { if (!is_admin()) return $slug; $slug = explode('-', $slug); foreach ($slug as $k => $word) { // стоп слова в wordpress чпу $keys_false = 'a,about,above,across,after,again,against,all,almost,alone,along,already,also'; $keys = explode(',', $keys_false); foreach ($keys as $l => $wordfalse) { if ($word==$wordfalse) { unset($slug[$k]); } } } return implode('-', $slug); } |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.