Last active
February 10, 2025 04:25
-
-
Save joshbetz/689bfef4ce89fe48d19621744fd03138 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// A blogroll for WordPress | |
// To be used with the link manager plugin https://wordpress.org/plugins/link-manager/ | |
// More info: https://josh.blog/2024/05/blogrolls | |
namespace Blogroll; | |
function custom_rewrite_rule() { | |
add_rewrite_rule('^.well-known/recommendations.opml/?$', 'index.php?well_known_recommendations=1', 'top'); | |
} | |
add_action('init', 'Blogroll\custom_rewrite_rule'); | |
function custom_query_vars($query_vars) { | |
$query_vars[] = 'well_known_recommendations'; | |
return $query_vars; | |
} | |
add_filter('query_vars', 'Blogroll\custom_query_vars'); | |
function custom_template_include($template) { | |
if (get_query_var('well_known_recommendations')) { | |
return ABSPATH . 'wp-links-opml.php'; | |
} | |
return $template; | |
} | |
add_filter('template_include', 'Blogroll\custom_template_include'); | |
function add_recommendations_opml_link() { | |
printf('<link rel="blogroll" type="text/xml" href="%s" />', home_url('/.well-known/recommendations.opml')); | |
} | |
add_action('wp_head', 'Blogroll\add_recommendations_opml_link'); | |
function custom_rss_feed_item() { | |
printf("\t<source:blogroll>%s</source:blogroll>\n", home_url('/.well-known/recommendations.opml')); | |
} | |
add_action('rss2_head', 'Blogroll\custom_rss_feed_item'); | |
function blogroll_namespace() { | |
echo 'xmlns:source="http://source.scripting.com/"'; | |
} | |
add_action('rss2_ns', 'Blogroll\blogroll_namespace'); |
@ralexander-phi good catch, thanks! Should be fixed now.
I tried uploading this as a plugin to WordPress (as a .zip
), but I get this error:
Unpacking the package…
Installing the plugin…
The package could not be installed. No valid plugins were found.
Plugin installation failed.
Any ideas?
Will be blogging about it in the context of sharing blogrolls if I can get it up and running, and will add you to my blogroll! :- )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this should also add
xmlns:source="http://source.scripting.com/"
to therss
element to define the custom namespace. Without this RSS parsers can throw validation errors.