First, thanks for helping me out here, I really appreciate your time.
Let me give you a little background on what I’m trying to accomplish:
I’m working on a small site enhancement where I want to add a simple related posts widget within the content area of certain posts.
Now, for any given post, I have all of my post content stored in a variable. Let’s call it $content.
What I’m hoping to do is parse this $content string and insert the widget immediately after the second instance of an H3 tag.
This is an example of one of my failed attempts:
$widgetizedContent = explode("</h3>", $content);
$widgetizedContent[1] .= 'widget code';
$finalContent = implode($widgetizedContent, "<p>");
I’m not really sure where to go from here, and would appreciate any direction you could provide me.
Edit: This is the output:
<h3>This is my header text[this is the text I'm trying to insert]</h3>
Instead of inserting the widget code after the H3, it’s inserting it before the closing H3 tag. I don’t think I understand implode as well as I should:)
Based on your code, you can add text after the second
</h3>by pre-pending the text to the content after the tag (rather than the content before).Of course this blindly assumes there will be at least 2
</h3>tags, which may or may not suit your site.