{"id":232926,"date":"2023-01-31T14:24:00","date_gmt":"2023-01-31T11:24:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232926"},"modified":"2023-01-31T14:24:46","modified_gmt":"2023-01-31T11:24:46","slug":"como-expirar-links-dofollow-automaticamente-funcao-de-gerenciamento-de-links-seo-em-php","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/pt-pt\/como-expirar-links-dofollow-automaticamente-funcao-de-gerenciamento-de-links-seo-em-php\/","title":{"rendered":"Como expirar links DoFollow automaticamente (fun\u00e7\u00e3o de gerenciamento de links SEO em PHP)"},"content":{"rendered":"<p>Como expirar links DoFollow automaticamente (fun\u00e7\u00e3o de gerenciamento de links SEO em PHP)<\/p>\n<div class=\"sds-iframe-wrapper fitvidsignore\" style=\"position:relative;padding-top:56.25%;max-width:100%;\"><iframe allowfullscreen style=\"position:absolute;top:0;left:0;width:100%;height:100%;\" src=\"\/\/www.facebook.com\/v2.6\/plugins\/like.php\" frameborder=\"0\"><\/iframe><\/div>\n<p>Acho necess\u00e1rio gerenciar os hiperlinks no wordpress em um local centralizado. Como tenho muitos links dofollow que n\u00e3o s\u00e3o mais v\u00e1lidos (acess\u00edveis). Tornar esses links inv\u00e1lidos nofollow \u00e9 essencial para fins de Search Engine Optimization (SEO) \u2013 voc\u00ea \u00e9 respons\u00e1vel por remover backlinks mortos para evitar a puni\u00e7\u00e3o de SEO.<\/p>\n<p>Neste post, veremos as <a href=\"https:\/\/helloacm.com\/php-function-to-get-exchange-rate-between-cryptocurrency-btc-ltc-eth-to-fiat-currency\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">fun\u00e7\u00f5es do PHP<\/a> para gerenciar os links automaticamente para que voc\u00ea possa expirar automaticamente os links ou tornar outros links No-Follow em um s\u00f3 lugar. Voc\u00ea pode us\u00e1-lo em seu site e tamb\u00e9m funciona bem no WordPress \u2013 pode ser necess\u00e1rio modificar a fun\u00e7\u00e3o filho do seu tema WordPress para aplicar a transforma\u00e7\u00e3o de texto\/links.<\/p>\n<p>Primeiro, a seguinte fun\u00e7\u00e3o find_links recebe uma string HTML, ent\u00e3o voc\u00ea pode aliment\u00e1-la com a sa\u00edda HTML e ela analisar\u00e1 a string HTML e procurar\u00e1 por cada hiperlink:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>1\n2\n3\n4\n5\n6\n<\/pre>\n<\/td>\n<td>\n<pre><span>&lt;?php<\/span>\n<span>function<\/span> find_links<span>(<\/span><span>$htmlString<\/span><span>)<\/span><span>{<\/span>\n&nbsp; &nbsp; <span>$pattern<\/span> <span>=<\/span> <span>'\/&lt;a (.*?)href=[\"'](.*?)\/\/(.*?)[\"'](.*?)&gt;(.*?)&lt;\/a&gt;\/i'<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>$htmlString<\/span> <span>=<\/span> <span>preg_replace_callback<\/span><span>(<\/span><span>$pattern<\/span><span>,<\/span> <span>'process_links'<\/span><span>,<\/span> <span>$htmlString<\/span><span>)<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>return<\/span> <span>$htmlString<\/span><span>;<\/span>\n<span>}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code>&lt;?php\nfunction find_links($htmlString){\n    $pattern = '\/&lt;a (.*?)href=[\"'](.*?)\/\/(.*?)[\"'](.*?)&gt;(.*?)&lt;\/a&gt;\/i';\n    $htmlString = preg_replace_callback($pattern, 'process_links', $htmlString);\n    return $htmlString;\n}<\/code><\/pre>\n<p>Como voc\u00ea pode notar, o regex est\u00e1 chamando de volta os process_links para cada <a href=\"https:\/\/wordpress.mediadoma.com\/pt-pt\/usando-a-expressao-regular-para-substituir-links-externos-no-wordpress-para-fins-de-seo\/\" title=\"hiperlink\">hiperlink<\/a> encontrado. E a seguir, voc\u00ea pode adicionar o dom\u00ednio do seu site na matriz $good_domains. E voc\u00ea pode definir dom\u00ednios expirando e suas datas de expira\u00e7\u00e3o correspondentes para que os links se tornem automaticamente NOFOLLOW.<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n<\/pre>\n<\/td>\n<td>\n<pre><span>&lt;?php<\/span>\n<span>function<\/span> process_links<span>(<\/span><span>$m<\/span><span>)<\/span><span>{<\/span>\n&nbsp; &nbsp; <span>$good_domains<\/span> <span>=<\/span> <span>array<\/span><span>(<\/span>\n&nbsp; &nbsp; &nbsp; <span>\"<a target=\"_blank\" href=\"https:\/\/helloacm.com\/\" rel=\"nofollow noopener\"><span>helloacm<\/span><span>.<\/span><span>com<\/span><\/a>\"<\/span>\n&nbsp; &nbsp; <span>)<\/span><span>;<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>$expiring_domains<\/span> <span>=<\/span> <span>array<\/span><span>(<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>\"<a target=\"_blank\" href=\"http:\/\/fakedomain.com\/\" rel=\"nofollow noopener\"><span>fakedomain<\/span><span>.<\/span><span>com<\/span><\/a>\"<\/span> <span>=&gt;<\/span> <span>\"2099-01-01\"<\/span>\n&nbsp; &nbsp; <span>)<\/span><span>;<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>$nofollow<\/span> <span>=<\/span> <span>\"rel=<span>\"<\/span>nofollow<span>\"<\/span>\"<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>$target<\/span> <span>=<\/span> <span>\"target=<span>\"<\/span>blank<span>\"<\/span>\"<\/span><span>;<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>$m<\/span><span>[<\/span><span>2<\/span><span>]<\/span> <span>=<\/span> <span>strtolower<\/span><span>(<\/span><span>$m<\/span><span>[<\/span><span>2<\/span><span>]<\/span><span>)<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>if<\/span> <span>(<\/span><span>(<\/span><span>$m<\/span><span>[<\/span><span>2<\/span><span>]<\/span> <span>!=<\/span> <span>\"https:\"<\/span><span>)<\/span> <span>&amp;&amp;<\/span> <span>(<\/span><span>$m<\/span><span>[<\/span><span>2<\/span><span>]<\/span> <span>!=<\/span> <span>\"http:\"<\/span><span>)<\/span><span>)<\/span> <span>{<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>$m<\/span><span>[<\/span><span>2<\/span><span>]<\/span> <span>=<\/span> <span>\"\"<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>}<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>\/\/$domain = str_lower(parse_url($m[3], PHP_URL_HOST));<\/span>\n&nbsp; &nbsp; <span>$domain<\/span> <span>=<\/span> getDomainName<span>(<\/span><span>$m<\/span><span>[<\/span><span>3<\/span><span>]<\/span><span>)<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>$curDomain<\/span> <span>=<\/span> <span>$_SERVER<\/span><span>[<\/span><span>'SERVER_NAME'<\/span><span>]<\/span> ?? <span>\"\"<\/span><span>;<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>if<\/span> <span>(<\/span><span>in_array<\/span><span>(<\/span><span>$domain<\/span><span>,<\/span> <span>$good_domains<\/span><span>)<\/span> <span>||<\/span> <span>(<\/span><span>$curDomain<\/span> <span>==<\/span> <span>$domain<\/span><span>)<\/span><span>)<\/span> <span>{<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>$nofollow<\/span> <span>=<\/span> <span>\"\"<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>}<\/span>\n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>if<\/span> <span>(<\/span><span>$curDomain<\/span> <span>==<\/span> <span>$domain<\/span><span>)<\/span> <span>{<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>$target<\/span> <span>=<\/span> <span>\"\"<\/span><span>;<\/span>\n&nbsp; &nbsp; <span>}<\/span> &nbsp; &nbsp; &nbsp; \n&nbsp; &nbsp; \n&nbsp; &nbsp; <span>if<\/span> <span>(<\/span><span>in_array<\/span><span>(<\/span><span>$domain<\/span><span>,<\/span> <span>array_keys<\/span><span>(<\/span><span>$expiring_domains<\/span><span>)<\/span><span>)<\/span><span>)<\/span> <span>{<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>$expiry<\/span> <span>=<\/span> <span>$expiring_domains<\/span><span>[<\/span><span>$domain<\/span><span>]<\/span><span>;<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>$today<\/span> <span>=<\/span> <span>date<\/span><span>(<\/span><span>\"Y-m-d\"<\/span><span>)<\/span><span>;<\/span> \n&nbsp; &nbsp; &nbsp; &nbsp; <span>if<\/span> <span>(<\/span><span>$today<\/span> <span>&lt;<\/span> <span>$expiry<\/span><span>)<\/span> <span>{<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span>$nofollow<\/span> <span>=<\/span> <span>\"\"<\/span><span>;<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; <span>}<\/span> &nbsp; &nbsp; &nbsp; &nbsp;\n&nbsp; &nbsp; <span>}<\/span>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \n&nbsp; &nbsp; <span>return<\/span> <span>\"&lt;a <span>$nofollow<\/span> <span>$target<\/span> href=<span>\"<\/span><span>{$m[2]}<\/span>\/\/<span>{$m[3]}<\/span><span>\"<\/span>&gt;<span>{$m[5]}<\/span>&lt;\/a&gt;\"<\/span><span>;<\/span>\n<span>}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code>&lt;?php\nfunction process_links($m){\n    $good_domains = array(\n      \"<\/code><\/pre>\n<p>A fun\u00e7\u00e3o altera duas propriedades de um hiperlink: _target que ser\u00e1 _blank quando for dom\u00ednio externo e rel que ser\u00e1 definido como nofollow automaticamente. Voc\u00ea tamb\u00e9m pode adicionar l\u00f3gicas para uniformizar todos os URLs, por exemplo, reescritas autom\u00e1ticas de HTTPS, r\u00f3tulos de hiperlink etc.<\/p>\n<p><a href=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-155416-61e55ed6698ca.jpg\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-155416-61e55ed6698ca.jpg\" alt=\"Como expirar links DoFollow automaticamente (fun\u00e7\u00e3o de gerenciamento de links SEO em PHP)\"><\/a><\/p>\n<p>\u2013EOF (<a href=\"https:\/\/helloacm.com\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">The Ultimate Computing &amp; Technology Blog<\/a>) \u2014<\/p>\n<p>Classifica\u00e7\u00e3o: 10,0\/ <strong>10<\/strong> (1 voto expresso)<\/p>\n<div class=\"sds-iframe-wrapper fitvidsignore\" style=\"position:relative;padding-top:56.25%;max-width:100%;\"><iframe allowfullscreen style=\"position:absolute;top:0;left:0;width:100%;height:100%;\" src=\"\/\/www.facebook.com\/v2.6\/plugins\/like.php\" frameborder=\"0\"><\/iframe><\/div>\n<p>536 palavras<br \/>\n<strong>\u00daltimo Post<\/strong>: <a href=\"https:\/\/helloacm.com\/teaching-kids-programming-converting-spreadsheet-column-titles-to-number\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Ensinando Programa\u00e7\u00e3o para Crian\u00e7as \u2013 Convertendo T\u00edtulos de Colunas de Planilhas em N\u00famero<\/a><br \/>\n<strong>Pr\u00f3ximo Post<\/strong>: <a href=\"https:\/\/helloacm.com\/teaching-kids-programmaing-generate-prime-numbers-using-sieve-of-eratosthenes-algorithms\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Ensinando Programando Crian\u00e7as \u2013 Gerando N\u00fameros Primos usando Algoritmos de Peneira de Erat\u00f3stenes<\/a><\/p>\n<p>A URL permanente \u00e9: <a href=\"https:\/\/helloacm.com\/how-to-expire-dofollow-links-automatically-seo-links-management-function-in-php\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Como expirar links DoFollow automaticamente (fun\u00e7\u00e3o de gerenciamento de links de SEO em PHP)<\/a> <a href=\"https:\/\/helloacm.com\/how-to-expire-dofollow-links-automatically-seo-links-management-function-in-php\/amp\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">(vers\u00e3o AMP)<\/a><\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Fonte de grava\u00e7\u00e3o:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Como expirar links DoFollow automaticamente (fun\u00e7\u00e3o de gerenciamento de links SEO em PHP)<\/p>\n","protected":false},"author":1,"featured_media":224449,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[898,998,806,1009,846,867],"tags":[1170],"class_list":["post-232926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codigo-2","category-marketing-de-conteudo","category-php-8","category-seo-9","category-tutoriais","category-wordpress-8","tag-affiai-pt-pt"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/posts\/232926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/comments?post=232926"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/posts\/232926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/media\/224449"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/media?parent=232926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/categories?post=232926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/pt-pt\/wp-json\/wp\/v2\/tags?post=232926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}