Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using shortcodes to insert some image links to my posts I grab from XML files (by an ID). As this needs to be executed just once it's not necessary to this everytime a user loads the page. So how can I replace the Shortcode with the needed content as soon as i save/publish/update the page?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

That's not how shortcodes work. Shortcodes are meant to be interpreted whenever the page is rendered - they're used when WordPress filters the page/post content.

What you're looking for is a content template. A tag the user can add to the page that will be converted into something else when the post is saved, like an RTF tag in a mail merge.

There's a filter that's run before posts are inserted into the database: wp_insert_post_data. This filter will pass the data for the to-be-inserted post as an array. You can take that array, parse your custom tags into whatever content you need, and pass it back before it's saved to the database.

Just filter $data["post_content"] and $data["post_content_filtered"] to make your replacement before passing the $data array back.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.