I want to add a disclaimer text to every post with a link. From what I’ve seen before, the basic format is below:
add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
function filter_the_content_in_the_main_loop( $content ) {
// Check if we're inside the main loop in a single post page.
if ( is_single() && in_the_loop() && is_main_query() ) {
return esc_html__("This website is intended to inform and educate, and shouldn't be taken as financial advice. It also uses affiliate links, including those from Amazon. If you make a purchase via one of the links marked with an *, we might receive a small commission. Find out more here.").$content;
}
return $content;
}
What’s the extra bit of code I need to turn "Find out more here" into a link to a specific page on the website?
I haven’t seen anything that includes a link as well as text.
2
Answers
You can edit your return string to include an hyperlink (or any HTML), like this:
You will need to remove the esc_html part, since this will escape the HTML you are returning, rendering it useless.
The links or other HTML getting removed because you are using
esc_html__
which is basically escape the HTML.In order to fix this either you can remove
esc_html__
or usewp_kses_post
function.