walid Posted December 1, 2022 Share Posted December 1, 2022 I am using wordpress an I am trying to dynamically add an ad to my content. I want the ad to show before the third h2 tag. How can I do this in php? I need something like: if third h2 tag,then echo "ads" before that h2 Quote Link to comment https://forums.phpfreaks.com/topic/315606-add-code-before-the-third-h3-tag/ Share on other sites More sharing options...
phppup Posted December 1, 2022 Share Posted December 1, 2022 I'm not familiar with the Word Press environment, but I would make these recommendations: Don't go backwards. Code isn't going to hit the brakes and jump into reverse. Give the h2 a CLASS <h2 class="ad_space"> Then search for ad_space. You can do an online search for PHP string functions and determine how you want to locate that sub-string (maybe use stripos to obtain a true/false) Quote Link to comment https://forums.phpfreaks.com/topic/315606-add-code-before-the-third-h3-tag/#findComment-1603137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.