Table of Contents

All links use a valid format

You are here:

This requirement ensure that all the links in your content (both external and internal) use a valid link format.

This feature won't check the destination URL, but it will check the link format to make sure you haven't used URLs such as htpps// or .nt.

Valid Format
Valid Format

If you enable this link validation option, it will be visible when you edit content.

If you have broken links in your content, this task will be marked in red in the sidebar:

Valid Format Red 1
Valid Format Red 1

If you do not have broken links, this task will be marked in green in the sidebar:

Valid Format Green
Valid Format Green

The Checklists plugin uses these regular expressions to check for broken links. You will find this code in this file: /core/Requirement/Validate_links.php.

//remove element inside <a href></a> to avoid double counting for one
//link in case of <a href="Link">Link</a>

$content = preg_replace("'\<a.*?href=\"(.*?)\".*?\>(.*?)\<\/a\>'si",'$1',$content);
$content = preg_replace("'\<a.*?href=\'(.*?)\'.*?\>(.*?)\<\/a\>'si",'$1',$content);

//strip html tags to avoid counting their link attribute as link
//like in <img src="" alt="" />

$content = strip_tags($content);

//remove any possible email from content so we don't count them as link

$content = preg_replace("/[^@\s]*@[^@\s]*\.[^@\s]*/", "", $content);

//match all links inside content

preg_match_all('~\b(?:https?://)?(?:(?i:[a-zA-Z0-9._-]+\.)+)[^\s,]+\b~', $content, $links);

Professional publishing plugins for WordPress! Get PublishPress