Yogenisia’s is right that you should use the_content
filter.
If you want to insert something before the first paragraph, locate the first <p>
in $content
, then insert your div
with substr_replace
.
add_filter( 'the_content', 'namespace_insert_before_first_paragraph' );
function namespace_insert_before_first_paragraph( $content ) {
$my_div = '<div> ... </div>';
$first_para_pos = strpos( $content, '<p' );
$new_content = substr_replace( $content, $my_div, $first_para_pos, 0 );
return $new_content;
}
Keep in mind however that many embeds, such as Twitter’s, wrap their content in a <p>...</p>
.
Related Posts:
- Stop WordPress Wrapping Images In A “P” Tag
- How to get ‘post_content’ without stripping tags?
- Get content from one page and show it on another page
- Removing any and all inline styles from the_content()
- How to disable content pagination?
- Modify ‘Read more’ link adding a new class
- Adding a div class or id inside the_content()
- Divide Post content into separate divs for every 500 characters (or any other character counts)
- Post content being duplicated by the_content();
- How can I extract the URL of a link from a post?
- Content editor creating blank paragraphs in spaces and creating   in the_excerpt
- How to add custom content (text/image) at start of content (IN content ie the same line)
- Testing for post title in ‘if/else’ statement returns no content
- Display the Content of a Post with qTip2
- How to show video from specific category on sidebar?
- custom post type grid with content in lightbox [closed]
- Uppercase first sentence in every post
- Why content_arr[‘extended’] removes paragraph tags?
- Modify Image Source With The_Content Filter?
- How to add pagination in between post and comments?
- Adding the_date inside tags around the_content
- Show the content that is after the excerpt using child theme
- get query() without post content?
- How to show full post?
- Filter only the text in the_content
- How to check if single.php has already called the_post_thumbnail function
- How to disable the_excerpt from one post
- the_content() Not Grabbing All Content
- Adding if statement into the_content()
- why my urdu text is not aligned properly when written in wordpress blog post?
- How do I display main query posts in random order using add_filter
- How to exclude native lazy loading from first image in post content?
- How to limit wordpress the_excerpt() dynamically
- how can i take wordpress post as embed?
- if CPT content is empty then
- Find post tags words in post content and link them to tag URLs
- Add review box by function at top or bottom of content
- Add Image Before Posts Entry Title
- Showing content from WordPress ruins page CSS using WP_Query, without, content does not show
- Assign custom class to post content images
- the_content() not displaying the full post
- Stripping tag from elements in post
- How add class the_content();?
- How to change the case of all post titles to “Title Case”
- How set featured posts using checkbox in post edit screen?
- Display posts by tag on page
- How to batch update post content with custom post meta value
- How to remove bulk edit options
- How to create post in WP network using WP-CLI
- How do I add a reusable block to a programmatically created post?
- ‘Invalid post type’ error when importing from one site to another
- The ‘https_local_ssl_verify’ filter
- Locked/Unlocked in title
- Category Template: Need to display different content on first page of archives
- Get image from post’s gallery
- check if wordpress is updating or publishing a post
- WordPress blog or WordPress website
- List blocks created by a specific block plugin
- Sort WP posts by span value
- How to sort posts inside categories
- Why does my site often display 404 on subpages?
- Move comments only from one WP installation to another
- How to change the color theme per post?
- Copy post to separate database with “add_action(….)”
- Do all wordpress themes a similar class name for content?
- Display Notification Bar on Header on Certain Post Count
- How do I do a page break?
- Thumbnail Image to go in the post aswell
- Loop parent terms {display posts} AND loop child terms {display posts}
- Print out last 3 blogposts
- Is there a query string for edit.php to show all posts that have no custom taxonomy terms?
- Edit post locked notification dialog on edit post screen (post.php)… hook maybe?
- wp_posts table extremely large
- Only allow posts with a specific term to only be viewed by other authors with the same term in their post
- Queries take 120+ seconds on my large WordPress site
- How to remove “» (title of post or page)”?
- Extract wordpress posts content and category content
- WordPress loop not working on static front page
- Multiple Blog Pages
- Change modified date to current date when title updated automatically
- how to Update guid = “text”+post_name?
- SQL DELETE multiple post_meta on single and multi-sites
- How to Best Create Separate Subscribers and User Experience
- Post not using taxonomy template
- query posts with selected post ids first
- How to display related post from same category in single.php
- Save All Post Permalink From A Specific Category into a .txt file
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- Using WP page password protection as defacto login
- get current index of post content in category page
- Permalink structure for two seperate blogs
- wp_query args with relation
- How do I apply a wordpress function to something with no ID inside an archive page?
- Add new post only in assigned category
- How to change post template via url?
- How do I list categories and the common categories for posts beneath those categories?
- How to remove a date from wordpress post
- wordpress pinboard theme [closed]
- How to automatically convert a form with HTML link into post
- WordPress Post Updating is Not Working