WordPress.org

Forums

WordPress Popular Posts
[resolved] [Plugin: WordPress Popular Posts] [Plugin: WordPress Popular Post] How prevent specific code to appe (8 posts)

  1. martinperreault
    Member
    Posted 4 years ago #

    Hi!
    How do I prevent from specific code to appear in the excerpt? For instance, I use a Youtube Plugin that requires the following code to be added in my posts for the video to appear:
    httpvh://www.youtube.com/watch?v=CODE

    I would like this line to NOT appear in the excerpts. How?

    See this screenshot from visual reference:
    http://img238.imagevenue.com/img.php?image=27186_capture_123_179lo.jpg

    Thanks for your help!

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 4 years ago #

    Hi Martin,

    For that, it is necessary to hack the excerpt method built-in in my plugin to remove these links before returning the text. Will look into this and come back with a patch so you can test it.

  3. martinperreault
    Member
    Posted 4 years ago #

    Thanks so much Ikki24!!!
    If I may make a suggesiton: it would be nice if there was a field in WP for the plugin where we could add codes manually that we wish to exclude from appearing. I have no idea how complicated it is to implement, so bare in mind this is only a suggestion. :-) Thanks again very much for looking into this!!

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 4 years ago #

    Hey Martin,

    Think I got something working. Please download v2.1.5 beta here and let me know the results, alright? It should filter out all these custom Youtube links (and added other extra stuff that should be stripped out, too).

    Been thinking about yor idea and while I think it's great, it's also a bit difficult to implement now. Will keep it in mind, though!

  5. martinperreault
    Member
    Posted 4 years ago #

    You rock Ikki24! Works like a charm. The bad youtube codes are gone. Thanks so much!

    No worries about my previous suggestion. I had a feeling it might be complicated to implement...

    That said, any idea how I could implement what you did in your plugin into "the_excerpt_rereloaded" plugin (which is what I am using on the front page for the excerpt of older posts)? The excerpt are behaving similarly, and the youtube codes do appear on the excerpt texts... So far no answer from the author of that plugin. I figured since you just tackled this subject, perhaps you`d have a quick fix for that plugin too?

    Thanks a bunch!

  6. Héctor Cabrera
    Member
    Plugin Author

    Posted 4 years ago #

    I believe this should do it:

    Open the_excerpt_rereloaded.php and change this code (around line 58):

    $text = preg_replace('/\[.*\]/', '', strip_tags($post->post_content, $allowed_tags));

    ... into this:

    $text = preg_replace('/\[.*\]/', '', strip_tags($post->post_content, $allowed_tags));
    
    // remove smart youtube links
    $text = preg_replace("/http(v|vh|vhd|vp):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^\s<]*)/", "", $text);
  7. martinperreault
    Member
    Posted 4 years ago #

    You, SIR, are a Godsent!
    It worked.
    I will keep this code as a reference.

    Thanks so much!

  8. Héctor Cabrera
    Member
    Plugin Author

    Posted 4 years ago #

    You're welcome :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic