The make_url_footnote() WordPress PHP function searches for all links in a given content, strips them out, and places them at the bottom of the content with numbers.
Usage
$content_with_footnotes = make_url_footnote($content);
Parameters
$content
(string) – Required. Content to process and extract links from.
More information
See WordPress Developer Resources: make_url_footnote
Examples
Basic usage
Convert links within a blog post content into footnotes.
$content = "Visit our website at <a href='https://example.com'>example.com</a> and read our blog post at <a href='https://example.com/blog'>example.com/blog</a>."; $content_with_footnotes = make_url_footnote($content); // Output: "Visit our website at [1] and read our blog post at [2]. [1] https://example.com [2] https://example.com/blog"
Extract links from a product description
Strip links from a WooCommerce product description and place them as footnotes.
$product_description = "Learn more about our product at <a href='https://example.com/product'>example.com/product</a>."; $product_description_with_footnotes = make_url_footnote($product_description); // Output: "Learn more about our product at [1]. [1] https://example.com/product"
Handle multiple paragraphs
Convert links within multiple paragraphs to footnotes.
$content = "<p>Welcome to our blog. Visit our homepage at <a href='https://example.com'>example.com</a>.</p><p>Read our latest article at <a href='https://example.com/article'>example.com/article</a>.</p>"; $content_with_footnotes = make_url_footnote($content); // Output: "<p>Welcome to our blog. Visit our homepage at [1].</p><p>Read our latest article at [2].</p> [1] https://example.com [2] https://example.com/article"
Process user comments
Strip links from user comments and place them as footnotes to avoid link spamming.
$comment_content = "Check out this amazing website: <a href='https://example.com'>example.com</a>."; $comment_content_with_footnotes = make_url_footnote($comment_content); // Output: "Check out this amazing website: [1]. [1] https://example.com"
Handle content with no links
Process content with no links; the function returns the original content unaltered.
$content = "This is a sample content with no links."; $content_with_footnotes = make_url_footnote($content); // Output: "This is a sample content with no links."