Skip to main content
100%

Автоматическое добавление атрибута nofollow ко всем внешним ссылкам в постах

✓ Published0🌍 Public
KKopylovVitalik
Last edited Oct 8, 2020
Created on Jul 23, 2020

This example demonstrates a WordPress PHP filter that automatically adds the `rel="noreferrer noopener nofollow"` attribute and `target="_blank"` to all external links within post content. It uses the `preg_replace_callback` function to scan for anchor tags, then applies regular expressions to check for existing `rel` attributes and the site’s own URL. The code hooks into the `the_content` filter via `add_filter`, processing HTML and modifying link markup to prevent search engines from following external links.

AI-generated description

Similar vizzes