Você deseja adicionar um link externo como título de postagem no WordPress? Às vezes, você pode querer apenas compartilhar um link com seus usuários. Em vez de enviá-los para uma postagem, talvez você queira que o título da postagem tenha um link para o outro site. Neste artigo, mostraremos a você como vincular links externos a partir do título da postagem no WordPress.
Método 1: Como vincular o título da postagem a um link externo no WordPress usando o plug-in
Esse método é mais fácil e é recomendado para iniciantes.
A primeira coisa que você precisa fazer é instalar e ativar o plugin Page Links To. Para obter mais detalhes, consulte nosso guia passo a passo sobre como instalar um plug-in do WordPress.
Após a ativação, basta criar uma nova postagem ou editar uma já existente. Você notará a nova meta box “Page Links To” abaixo do editor de posts.
Clique em “A custom URL” para adicionar o link que você deseja adicionar ao título da postagem. Agora você pode salvar ou publicar sua postagem.
Isso é tudo. O título da postagem agora terá um link para o URL personalizado que você forneceu.
Não é necessário usá-lo somente para links externos. Você também pode usá-lo para enviar usuários a diferentes posts e páginas no seu site WordPress.
Método 2: Adicionar link externo ao título da postagem usando o código
Esse método exige que você adicione código ao seu site WordPress. Você pode usar esse método se estiver acostumado a colar trechos da Web no WordPress.
Basta adicionar esse código ao arquivo functions.php do seu tema ou a um plug-in específico do site.
function print_post_title() { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $perm = get_permalink($post_id); $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey=='external_url') { $post_val = get_post_custom_values($pkey); } } if (empty($post_val)) { $link = $perm; } else { $link = $post_val[0]; } } else { $link = $perm; } echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>'; }
Esse código simplesmente procura por um campo personalizado que contenha seu URL personalizado. Se o post tiver o campo personalizado, ele produzirá o título do post vinculado ao seu URL.
A próxima etapa é substituir a exibição padrão do título da postagem em seu tema por essa função. Você a encontrará em archives.php, content.php, category.php e outros modelos. A aparência seria mais ou menos assim:
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
Você precisa substituí-lo por este código:
<?php print_post_title() ?>
A parte do código está concluída, agora você precisa adicionar o URL externo à postagem. Basta editar a postagem ou criar uma nova. Na página do editor de postagens, procure a meta-caixa de campos personalizados.
Se não conseguir ver a meta-caixa de campos personalizados, clique em Screen Options (Opções de tela ) no canto superior direito da tela. Isso abrirá um menu no qual você precisará marcar a caixa ao lado de “Custom Fields” (Campos personalizados).
Você encontrará a meta-caixa de campos personalizados abaixo do editor de posts.
Clique em “Enter New” (Inserir novo ) e insira external_url
no campo “Name” (Nome) e o URL que você deseja adicionar ao título do post no campo“Value” (Valor).
Agora você pode salvar ou publicar sua postagem. Isso é tudo, o título da postagem agora estará vinculado ao URL que você adicionou no campo personalizado.
Da próxima vez que precisar adicionar um link, basta selecionar o campo personalizado external_url
no menu suspenso e inserir o link externo no campo de valor.
Esperamos que este artigo tenha ajudado você a aprender como criar links externos a partir do título da postagem no WordPress. Talvez você também queira ver nosso guia sobre como adicionar um ícone de link externo em seu site WordPress.
Se você gostou deste artigo, inscreva-se em nosso canal do YouTube para receber tutoriais em vídeo sobre o WordPress. Você também pode nos encontrar no Twitter e no Facebook.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
John says
Will this work on images relating to the post titles as well? So clicking on either image or post title takes you to the page on the external site?
WPBeginner Support says
The plugin would do that for your featured image if that is what you mean.
Administrador
Alessandro says
is there a way to link post titles to custom links, but only if they are present in one page (so not for the whole site)?
Example: search results page of plugins like search & filter or toolset
WPBeginner Support says
We do not have a recommended method for setting that up at the moment.
Administrador
Kam says
Thank you. This is really helpful. Would this plugin work for automated RSS feeds? i.e. for aggregator sites? I’m assuming no, as the titles are constantly changing. I’m trying to take the user to the original source with one click on the title.
WPBeginner Support says
You would want to reach out to the support for the aggregator tool you are using for the options you have available.
Administrador
Sing says
Is the above method and Content syndication are one and the same? Or both are different topic.
WPBeginner Support says
That is a different topic
Administrador
Maksym says
Amazing! This is what I was looking for. Thank you so much
WPBeginner Support says
Glad our article was helpful
Administrador
mostafa says
Thank you for this tutorial. It helped me a lot but how to use this for cpt (in my case a testimonial) and open the link in a new tab . Thank you.
WPBeginner Support says
You’re welcome
Administrador
Brandon H. says
You saved my website! Thank you so much!!
mehmet says
Thank you for useful information.
My English is a little bad.
I want to use this kind of plugin on my site
But the bold type in the text will be automatically linked to the text.
Links to other posts within the site
Is there such an extension?
martin says
Thanks for that, pretty helpful. Found a lot of help on this site already!
Best from Italy,
Martin
Tammy says
Is there a way to require the external url to be unique? I’m using wp-directory and would love to be able to make this custom field “unique required”
Melch Wanga says
Its a good post indeed. In response to Toni, in my case I am developing a website for film production company and I have “Equipment Hire” as a services in ‘service’ custom post type. Equipment Hire is quite huge and I am using WooCommerce to add the various equipment hence I have Shop page that lists all the equipment available for hire. The trick is to ensure that whenever a user clicks on “Equipment Hire” service, they are directed to the Page set as the Shop page instead of the default Equipment Hire single post page.
Mel says
Hi, how is this going to affect SEO? Can we add rel=”nofollow” to an external link?
Thanks
Ariel says
great post!
Palashtd says
Recently I have started blogging.
I could think how to add External Links from the Post Title. But finally I got an awesome tip from this post. I have tested by following this tutorial. I am happy to get these tips because it’s working for me.
Thanks for sharing this information.
Toni Weidman says
I’m not sure why you would want to do this. Can you clarify what the purpose of this process is. Thank you.