0

I'm trying to send emails showing my post contents when I publish something on my site. However, my posts have videos so I'm trying to remove that from the emails that go out. Here is the current code using

// Get post description
        $post_description_length = 1000;
        $post_description        = $post->post_content;
        $post_description        = strip_tags( strip_shortcodes($post_description ) );
        $words                   = explode( ' ', $post_description, $post_description_length + 1 );

With the above, it removes the video from my post. However, my posts are in bullet point format so with the above code, it is stripping all the tags so my post loses formatting once it becomes an email and just becomes one big paragraph. How can I edit the above so it just focuses on the shortcode for the video. The video uses a shortcode 'videopack' to display the video from my server on my posts. ex. [videopack id="293877"]Video link here[/videopack]

4
  • Does your post content have shortcodes that you don't want to remove? If not, then have you tried removing the call to strip_tags()?
    – ScottM
    Jun 24 at 11:18
  • Hey Scott, I just want to remove the [videopack] code. I want to keep all the formatting like bolding, paragraphs, etc. I guess how do I change the coding above to make it only remove the [videopack] part
    – Jeremy
    Jun 24 at 13:59
  • Here is an example. I want to keep all the shortcodes but remove the tag. So would I just delete the strip tag part? [videopack][/videopack] <strong>INCIDENT DATE/TIME</strong>: <strong>LOCATION</strong>: <strong>CITY</strong>: <strong>DETAILS</strong>: <ol> <li>Detail</li> </ol> <strong>HANDLING AGENCIES</strong>: <strong>SOT(s)</strong>: N/A
    – Jeremy
    Jun 24 at 14:02
  • Hi Jeremy - if you remove the call to strip_tags() in the one line like this - $post_description = strip_shortcodes($post_description ); - what result do you get?
    – ScottM
    Jun 24 at 14:43

1 Answer 1

0

The following regex should do the trick to select all instances of the videopack shortcode, including contents: \[videopack.*?\[\/videopack\]

$post_description = preg_replace( '\[videopack.*?\[\/videopack\]', '', $post->post_content );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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