• Hey guys,

    I’ve been struggling with this whole morning.

    So in each of my posts I have special code with a banner image.

    <p>
    <banner></banner>
    </p>

    It’s an image which is styled within CSS so I can easily replace it when needed.

    What I want now is to add special code ABOVE that paragraph, Javascript code to be precise.

    I’ve tried playing around with preg_replace but couldn’t get it to work at all, it would make whole post go blank.

    Would be someone be kind enough to help me out with simple example so I’ll work my way up?

    eg: If you have this:

    <p>
    <banner></banner>
    </p>

    How do I make it be this:

    <script type="text/javascript" src="js"></script>
    <p>
    <banner></banner>
    </p>

    So just to add that JS code above that specific paragraph.

    Thank you very much for any tips!

    PS. I could do that by editing each post separately (if I’m allowed to post javascript within post content?) but I’ll also have to do it for each new post and then if I want to remove it I’ll have to go through ton of posts to remove it again. Which is why I think doing this would be much cleaner solution.

  • The topic ‘Append Custom Code in Post on Exact Location’ is closed to new replies.