|
@@ -361,4 +361,30 @@ function captivating_wprm_buttons() {
|
|
}
|
|
}
|
|
echo '</div>';
|
|
echo '</div>';
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+//* ##################################################################### *//
|
|
|
|
+//* Add Amazon statement after after 2nd paragraph of single post content.
|
|
|
|
+
|
|
|
|
+add_filter( 'the_content', 'prefix_insert_post_ads' );
|
|
|
|
+function prefix_insert_post_ads( $content ) {
|
|
|
|
+ $ad_code = '<div class="aws_statement"><p>This post may contain Amazon or other affiliate links. As an Amazon associate, I earn from qualifying purchases. If you purchase anything through any affiliate link, I may earn a small commission at no extra charge to you. All opinions are my own.</p></div>';
|
|
|
|
+ if ( is_single() && ! is_admin() ) {
|
|
|
|
+ return prefix_insert_after_paragraph( $ad_code, 2, $content );
|
|
|
|
+ }
|
|
|
|
+ return $content;
|
|
|
|
+}
|
|
|
|
+function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
|
|
|
|
+ $closing_p = '</p>';
|
|
|
|
+ $paragraphs = explode( $closing_p, $content );
|
|
|
|
+ foreach ($paragraphs as $index => $paragraph) {
|
|
|
|
+ if ( trim( $paragraph ) ) {
|
|
|
|
+ $paragraphs[$index] .= $closing_p;
|
|
|
|
+ }
|
|
|
|
+ if ( $paragraph_id == $index + 1 ) {
|
|
|
|
+ $paragraphs[$index] .= $insertion;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return implode( '', $paragraphs );
|
|
}
|
|
}
|