- This topic has 3 replies, 2 voices, and was last updated 2 years, 11 months ago by
Fernando.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
April 2, 2023 at 10:28 am #2593419
Gabriel
Hello, my affiliate disclosure insert on blog posts only is now messed up since the recent Gneratepress update. Basically, now instead of the disclosure statement showing after the first paragraph, it is showing at the very bottom of the copy.
I have included the code below. Your team provided this code a while back to someone else, but I modified it with my disclosure statement. Can you please tell me what’s wrong?
The code is in WordPress functions.php ( I use a child theme).
/* insert disclosure */ add_filter( 'the_content', 'db_prefix_first_h2_custom_html' ); function db_prefix_first_h2_custom_html( $content ) { $html = '<div><p><small><strong>Quick disclosure:</strong> Some links on this page are affiliate links. We may earn revenue at no additional cost to you if you purchase using the links. We greatly appreciate your support.</small></p></div>'; if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $html, 1, $content ); } return $content; } function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '<h2>'; $paragraphs = explode( $closing_p, $content ); if ($paragraphs) { $paragraphs[0] = $paragraphs[0].$insertion; } return implode( '<h2>', $paragraphs ); } /* Disclosure end */April 2, 2023 at 6:33 pm #2593769Fernando Customer Support
Hi Gabriel,
For clarity, is the disclosure supposed to be after the first H2 or the first paragraph?
If it’s after the first paragraph, try this instead:
add_filter( 'the_content', 'db_prefix_first_h2_custom_html' ); function db_prefix_first_h2_custom_html( $content ) { $html = '<div><p><small><strong>Quick disclosure:</strong> Some links on this page are affiliate links. We may earn revenue at no additional cost to you if you purchase using the links. We greatly appreciate your support.</small></p></div>'; if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $html, 1, $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 ); }April 2, 2023 at 11:56 pm #2594018Gabriel
Worked perfectly. Thank you!
April 3, 2023 at 1:01 am #2594105Fernando Customer Support
You’re welcome, Gabriel!
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.