{"id":232932,"date":"2023-01-31T13:34:00","date_gmt":"2023-01-31T10:34:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232932"},"modified":"2023-01-31T13:34:57","modified_gmt":"2023-01-31T10:34:57","slug":"dofollow-linkide-automaatne-aegumine-seo-linkide-haldusfunktsioon-php-s","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/et\/dofollow-linkide-automaatne-aegumine-seo-linkide-haldusfunktsioon-php-s\/","title":{"rendered":"DoFollow linkide automaatne aegumine (SEO linkide haldusfunktsioon PHP-s)"},"content":{"rendered":"<p>DoFollow linkide automaatne aegumine (SEO linkide haldusfunktsioon PHP-s)<\/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>Leian, et WordPressi h\u00fcperlinke on vaja hallata tsentraalses kohas. Kuna mul on palju dofollow linke, mis enam ei kehti (juurdep\u00e4\u00e4setavad). Nende kehtetute linkide muutmine nofollow&#8217;ks on otsingumootori optimeerimise (SEO) jaoks kohustuslik \u2013 teie vastutate surnud tagasilinkide eemaldamise eest, et v\u00e4ltida SEO karistust.<\/p>\n<p>Selles postituses vaatleme <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\">PHP funktsioone<\/a> linkide automaatseks haldamiseks, et saaksite lingid automaatselt aeguda v\u00f5i muud lingid \u00fches kohas mittej\u00e4rgida. Saate seda kasutada oma veebisaidil ja see t\u00f6\u00f6tab h\u00e4sti ka WordPressis \u2013 v\u00f5ib-olla peate teksti\/linkide teisenduse rakendamiseks muutma oma WordPressi teema alamfunktsiooni.<\/p>\n<p>Esiteks v\u00f5tab j\u00e4rgmine funktsioon find_links HTML-stringi, nii et saate seda HTML-v\u00e4ljundiga toita ja see s\u00f5elub HTML-stringi ja otsib iga h\u00fcperlinki:<\/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>Nagu v\u00f5ite m\u00e4rgata, kutsub regex iga leitud <a href=\"https:\/\/wordpress.mediadoma.com\/et\/regulaaravaldise-kasutamine-wordpressi-vaeliste-linkide-asendamiseks-seo-eesmaerkidel\/\" title=\"h\u00fcperlingi jaoks tagasi protsessi_lingid.\">h\u00fcperlingi jaoks tagasi protsessi_lingid.<\/a> J\u00e4rgmisena saate lisada oma saidi domeeni massiivi $good_domains. Ja saate m\u00e4\u00e4rata aeguvad domeenid ja nende vastavad aegumiskuup\u00e4evad, nii et lingid muutuvad automaatselt NOFOLLOW-ks.<\/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>Funktsioon muudab h\u00fcperlingi kahte atribuuti: _target, mis on _blank, kui see on v\u00e4line domeen, ja rel, mis seatakse automaatselt v\u00e4\u00e4rtusele nofollow. Samuti saate lisada loogikaid k\u00f5igi URL-ide \u00fchtlustamiseks, nt HTTPS-i automaatsed \u00fcmberkirjutused, h\u00fcperlinkide sildid jne.<\/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=\"DoFollow linkide automaatne aegumine (SEO linkide haldusfunktsioon PHP-s)\"><\/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>) \u2013<\/p>\n<p>Hinnang: 10,0\/ <strong>10<\/strong> (1 h\u00e4\u00e4l)<\/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 s\u00f5na<br \/>\n<strong>Viimane postitus<\/strong>: <a href=\"https:\/\/helloacm.com\/teaching-kids-programming-converting-spreadsheet-column-titles-to-number\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Lastele programmeerimise \u00f5petamine \u2013 arvutustabeli veergude pealkirjade teisendamine numbriteks<\/a><br \/>\n<strong>J\u00e4rgmine postitus<\/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\">Laste programmeerimise \u00f5petamine \u2013 algarvude genereerimine Eratosthenese algoritmide s\u00f5ela abil<\/a><\/p>\n<p>Alaline URL on: <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\">DoFollow linkide automaatne aegumine (SEO linkide haldusfunktsioon PHP-s)<\/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\">(AMP versioon)<\/a><\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DoFollow linkide automaatne aegumine (SEO linkide haldusfunktsioon PHP-s)<\/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":[894,842,802,1005,994,863],"tags":[1165],"class_list":["post-232932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kood","category-opetused","category-php-4","category-seo-5","category-sisuturundus","category-wordpress-4","tag-affiai-et"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/posts\/232932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/comments?post=232932"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/posts\/232932\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/media\/224449"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/media?parent=232932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/categories?post=232932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/et\/wp-json\/wp\/v2\/tags?post=232932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}