You’re right, you can do that with a filter (the_content
). I attached an example. You can put that into the functions.php
of your theme.
function add_content_after_h2($content){
if (is_single()) {
$div = '<div>small bit of content</div>';
$content = preg_replace('/(<\/h2>)/i', '\1'.$div, $content);
}
return $content;
}
add_filter('the_content', 'add_content_after_h2');
Here you find the WordPress Codex with a detailed description of that filter:
https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
Related Posts:
- Only show content before more tag
- post_content with line breaks
- Why is the_content() not displaying the content? [closed]
- Heartbeat API oEmbed
- Apply the_content filter for specific post types only
- How to to stop html editor from addig tags to shortcodes, images, etc
- Static page homepage not showing the_content
- How to add an inline style to the tag outputted in the_content() using PHP?
- Word limit in post_content after more tag
- Is it possible to handle a specific section of a post separately?
- Is it possible to change the contents of “the_content()”?
- How to encode post content as JSON?
- How to output only the post content
- How I can split text in the_content() into 2 columns?
- How can I show the actual content of Posts page because the_content() is showing all blog content?
- the_content() isn’t showing content, but $post->post_content does
- preg_replace Remove comment text in content
- tag the_content()
- Add span to the first letter of post
- WordPress replacing all line breaks in comments with “rn”
- Proper use of the_content filtering
- put the content of a single post into og:description
- Output the_title() inside the_content()
- the_content is always surrounded by paragraphs (how to disable or remove them)?
- $content = $post->post_content; with formating
- Filter the_content() in the Quote Post Format to Display Quotes
- How to count rows of table in the_content()
- WordPress get_the_content get child element like p value
- Strip links from the_content
- Concatenate a Function to the Post Content
- How to change the position of Jetpack sharing icons? [closed]
- embed the_content
- Hook midway through the_content();?
- Appending code to the_content
- Missing content in Pages only
- Short Overview in AMP Version and Link to full article non-amp [closed]
- Changing Image Size In The Content tag
- the_content() – Getting formatted text
- limit how many words show up in the_content on index
- Problem on the_excerpt(); function
- How can I display “read more” without any other post text?
- WordPress appends the_content filtered text inside last paragraph tag of content (rather than after it)
- the_content() printing site title after page/post title and before its content
- WordPress adding content into different sections
- How to keep before/after text inline with nl2br and the_content()
- removing tags around img, iframes and also scripts
- Should I find/replace values in the_content?
- Remove images from the_content [duplicate]
- How to limit the characters shown on the page – get_content
- Extract a link in the_content()
- Content DISAPPEARS when simply adding normal text for ONE POST ONLY
- How do I show current post content in the header?
- strip_tags in get_the content
- the_content() returning unexpected div wrappers
- How can I output the content of the page using this code?
- filter h1 tag to add a word at the beginning of the text
- the_content() brings the medium size image [closed]
- How can i specify the size of the image rendered by the_content();?
- IF Inside A Function For Content Filter [closed]
- content and excerpt not displaying
- Get Content Limit?
- Append data to the_content within the database (not using filter)
- Post Format Link Validation Error
- the_content returns blank when adding SEO details
- how to include page content to specified length & then “read more” link
- How to add multiple the_content or something like that?
- Using str_replace on the_content and the_excerpt, but not working on archive index pages
- Get specific Blocks from Post
- Is there a difference in usage of the_title() and the_content()
- How to show Social share buttons outside the post?
- WordPress v5.4.2 escapes the content of Edit Attachment > Description field
- Remove pre and code tags from WordPress
- auto link word link in content
- How to parse any content which was added after the working out filter ‘the_content’
- One Content Filter To Rule Them All
- Extract links inside embed tags in WordPress
- Looking to limit the number of characters on my post page
- after setup_postdata, the_content() only displays text before the read more tag
- Remove P tag from images if aligncenter class is set
- Call the content help
- Remove a div with ID from the_content WordPress
- wp_content text length and displaying ‘more’ for the full text
- Modify Ixion Theme to Include Post Excerpt On Main Page
- Cannot Find Hook that is changing the_content()
- get_post_fields as an excerpt
- The_content is different from category archive to other pages [closed]
- the_content inside my own theme does not retain line breaks / enters like in the admin
- the_content() not working in my Android mobile
- Read more link for blog listing page
- Add read more to the_content
- pre_get_posts returning unformatted page
- How to replace text in hompage only
- How do I remove the title from the_content
- Exactly where I have to insert get_next_post_link() in a post?
- Does WP have a hook for the use of wp_trim_words?
- I want a part of the_content be under custom post types
- Find and replace weird characters in the_content [closed]
- How to remove only images from the_content() [duplicate]
- Adding schema to text content in the loop, how?
- How can I customize the_content(); output? [closed]