Find answers, ask questions, and connect with our
community around the world.

Activity Forums Web Design WordPress Requesting recommendations on best ways to get and replace text segments in a WP post’s content programmatically?

  • Requesting recommendations on best ways to get and replace text segments in a WP post’s content programmatically?

    updated 2 weeks, 2 days ago 0 Member · 1 Post
  • Deborah

    Member
    October 31, 2019 at 2:47 pm

    Lets say I have a post like like this: The American Civil War began in 1861 and ended in 1865. I want to parse this text and find each occurrence of (some characters) and replace it with Using the above example the ending output should be: The American Civil War began in and ended in I’m currently thinking about hooking onto the filter the_content for this purpose. Something like: function notes_blankit( $content ) { if ( is_single() && in_the_loop && is_main_query() ) { $content = preg_replace( ‘(.*?)’, ” ); return $content; } return $content; } add_filter( ‘the_content’, ‘notes_blankit’ ); Is this a good way to accomplish this? If not, what would be better? You’ll also notice there are a few places in above function that need to be fleshed out. Specifically: Grabbing the value captured by (.*?) and using it in the id of the generated input. Adding a unique value to the id of the generated output so it doesn’t end up creating inputs with the same id. Any feedback is welcomed. – by hq overview davidshq – –

Reply to: Deborah
Your information:

Cancel
Original Post
0 of 0 posts June 2018
Now