Hi there!
Guys, I have wrote some code and it adding some code )) before second h2, but it works only for classic editor’s posts.
How to make it correct for advanced editor’s posts?
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div style="display: flex; gap: 0.5rem;">
<div class="column"><a href="#"><img src="/uploads/2023/07/banner_fin_1.jpg" alt="image" /></a></div>
<div class="column"><a href="#"><img src="/uploads/2023/07/banner_fin_2.jpg" alt="image" /></a></div>
<div class="column"><a href="#"><img src="/uploads/2023/07/banner_fin_3.jpg" alt="image" /></a></div>
</div>';
if ( is_single() && ! is_admin() && in_category('152') ) {
return prefix_insert_after_paragraph( $ad_code, 1, $content );
}
return $content;
}
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '<h2>';
$paragraphs = explode( $closing_p, $content );
if ($paragraphs) {
$paragraphs[1] = $paragraphs[1].$insertion;
}
return implode( '<h2>', $paragraphs );
}
Thank you!
Hey mischael1,
Thank you for the inquiry.
How do you add the second h2 when using the Advance Layout Builder? If you’re using the Special Heading element, then the filter above will not work. You will have to modify the element template directly or override it. The template is located in the enfold/config-templatebuilder/avia-shortcodes/heading folder.
Best regards,
Ismael