Skip to content

Instantly share code, notes, and snippets.

@chellestein
Created June 17, 2022 11:09
Show Gist options
  • Save chellestein/0c109ae8163e2f6c369e11ad76fc37f7 to your computer and use it in GitHub Desktop.
Save chellestein/0c109ae8163e2f6c369e11ad76fc37f7 to your computer and use it in GitHub Desktop.
Add affiliate disclosure WP Snippet
/* Add affiliate disclosure before the content */
function my_content_filter($content){
//only add text before WordPress posts
if(is_single() && is_main_query()){
$before = '<div class="disclosure">This post may contain affiliate links, which means we may earn a commission if you make a purchase. As an Amazon Associate we earn from qualifying purchases. Thank you for your support!</div>';
$after = '<div class="after-entry"></div>';
//modify the incoming content
$content = $before . $content . $after;
}
return $content;
}
add_filter( 'the_content', 'my_content_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment