chevron-left chevron-right

Piotr Nalepa Frontend, architecture and AI

[WordPress] Jak zrobić własne, któtkie linki?

This version
blog.piotrnalepa.pl/2009/07/19/wordpress-jak-zrobic-wlasne-ktotkie-linki
Published
Author
, Staff Software Engineer
Category
Wordpress
Feedback
Write to me · Post on X

This post is 17 years old. Browsers and tools may have changed since then, so check the code against current documentation before you use it.

Jeśli korzystacie z Twittera to na pewno zauważyliście, że generuje on krótki linki, jeśli link jest dłuższy niż 30 znaków. Możliwe, ze zastanawialiście się jak to działa i jak to zrobić? Pokażę jak to zrobić.

Po pierwsze trzeba wstawić poniższe dwie linijki do pliku .htaccess:

RewriteCond %{REQUEST_URI} ^/([0-9]+)$
RewriteRule .* http://www.nazwastrony.pl/?p=%1 [R=301,L]

UWAGA! Na wszelki wypadek zróbcie kopię zapasową pliku .htaccess.

Następnie do kodu szablonu WordPress wstawcie w miejsce gdzie się pojawiają komentarze czy gdziekolwiek indziej pod artykułem następujący kod:

Example 1HTML
<a rel=?nofollow? href=?http://twitter.com/home/?status=Reading @sunpietro ? <?php the_title(); ?> https://blog.piotrnalepa.pl/<?php the_ID(); ?>?><img src=?https://blog.piotrnalepa.pl/images/twitt-me.png? alt=?Dodaj do Twittera? /><b>Zatwittuj mnie!</b></a>

Dzięki temu możecie mieć krótkie linki a'la Twitter. Nie trzeba się też martwić o to, że wasze linki nie będą już poprawne dla SEO po tym zabiegu, ponieważ Twitter zrobi przekierowanie na normalny link, a nie nowy skrócony.

Share
Feedback

About the author

Staff Software Engineer

I've been writing this blog since 2009 and building for the web professionally for 14 years. Today I lead the frontend of the Cosmos platform at Bishop Fox, where I've been since day one of the project. Before that I worked at OLX, KUDO, Auto1 and eZ Systems. Here I write about what I've learned in practice: JavaScript, TypeScript, React, CSS and frontend architecture. I've also spoken at conferences across Poland and Europe. Got a question or an idea for a post? Let me know!