Created
June 17, 2022 11:09
-
-
Save chellestein/0c109ae8163e2f6c369e11ad76fc37f7 to your computer and use it in GitHub Desktop.
Add affiliate disclosure WP Snippet
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
/* 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