Someone asked me to create a solution to use HTML anchors () in the WP blog tagline. E.g. like:
Just another <a href="http://www.wordpress.org">WordPress</a> website
I came up with a small plugin where the user can use pseudo-code in the tagline, which is converted by the plugin to HTML anchors. Something like
Just another [[http://www.wordpress.org]]WordPress[[/]] website
This works fine, however WordPress keeps encoding the HTML to entities, and I have no clue how to resolve or prevent this.
My best guess is that some other filter hook fires after my plugin, and maybe I need to use some other hook(?) I tried option_blogdescription and pre_option_blogdescription and both have the same effect. However, this is just a wild guess and even then, I don't know whch hook to use then.
Also I tried diffent ways of getting the tagline content (To prevent that it already arrived as entities) I tried to receive it directly from the hook parameter, getting with get_option, getting with $wpdb->get_results but all with the same result.
And I tried several things to decode it like html_entity_decode() and wp_kses(). Again, all with the same result.
But if everything is encoded after my plugin comes in, none of my effort will have any effect.
I have more versions. Two of the latest:
The Hook add_filter( 'option_blogdescription', 'add_html_blog_description' );
Function 1
function add_html_blog_description( $option_value ) {
$url = 'http://www.wordpress.org';
$tagopen = '[[';
$tagclose = ']]';
$option_value = str_replace($tagopen, '<a href="' . $url .' ">', $option_value);
$option_value = str_replace($tagclose, '</a>', $option_value);
return $option_value;
}
function 2
function add_html_blog_description( $option_value ) {
global $wpdb;
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array()
)
);
$results = $wpdb->get_results( "SELECT `option_value` FROM `wdwp_options` WHERE `option_name` = 'blogdescription'", ARRAY_A );
$new_tagline = $results[0]['option_value'];
$new_tagline = html_entity_decode (wp_kses( $new_tagline, $allowed_html ) );
return $new_tagline;
}