WordPress.org

Ready to get started?Download WordPress

Forums

Remove short code from excerpt (4 posts)

  1. Vcize
    Member
    Posted 3 years ago #

    I'm using the simple video embedder plugin on my site. To embed a video with it, you enter the short code [simple_video]

    The problem is, if it is near the beginning of my post, then on the main page it shows up in the excerpt field as just the raw text [simple_video]. I would like to make it either show the actual video, or just strip that text out altogether.

    I've googled this like crazy and there is lots of info but not really any solutions (at least not that worked for me). I played with filters a bit but they're a little over my head.

  2. Scott Bressler
    Member
    Posted 3 years ago #

    To remove a shortcode like:
    [media-credit param=value param2="value2"]text you actually want goes here[/media-credit]
    You can use the following to your functions.php file:

    add_filter( 'the_excerpt', 'remove_media_credit_from_excerpt' );
    function remove_media_credit_from_excerpt( $excerpt ) {
    	return preg_replace ('/\[media-credit[^\]]*\](.*)\[\/media-credit\]/', '$1', $excerpt);
    }

    I'm not sure how the [simple_video] shortcode works, but you should be able to adjust the above to make it work.

  3. jtrenor
    Member
    Posted 3 years ago #

    Thank you sbressler, this worked great for my WordPress site.

  4. SoBytes
    Member
    Posted 3 years ago #

    legend i had a similar problem great way to do it ;)

Topic Closed

This topic has been closed to new replies.

About this Topic