Support » Plugin: WordPress Popular Posts » Remove certain words from title of posts?

  • Resolved Wings69


    I didn’t see this option in the parameters so not sure it is possible or not but thought I would ask.

    Let’s say I have a website and all its post titles are:

    List of Tom Hanks Movies
    List of Brad Pitt Movies


    Is there anything I could do within the parameters to strip the words “List” “of” and “Movies” from the popular posts listing? So that in that example it would display it as:

    Tom Hanks
    Brad Pitt



Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Héctor Cabrera


    Hi @wings69,

    You won’t find any settings or options that can do this kind of stuff. For this you’ll need some custom coding work 😛

    You can use the undocumented wpp_the_title filter hook to modify the post title before WPP renders it on screen. For example:

     * Removes 'List', 'of', and 'Movies' from post title.
     * @param  string  $post_title  The post title.
     * @return string  $post_title  The (modified) post title.
    function trim_popular_posts_titles($post_title) {
        $title_arr = explode(' ', $post_title);
        $omit_words = array('list', 'of', 'movies');
        $new_title_arr = array_udiff($title_arr, $omit_words, 'strcasecmp');
        return implode(' ', $new_title_arr);
    add_filter('wpp_the_title', 'trim_popular_posts_titles');

    Untested but I think it should work.

    Thread Starter Wings69


    Oh wow – thank you so much both for the prompt response and the very detailed response! I will test that out tomorrow. Either way it is a great starting point.

    Thanks so much. I use your plugin on a few sites and it is great. Sending a donation your way just now for the awesome support! Cheers.

    Plugin Author Héctor Cabrera


    Don’t mention it, glad I could help! And thanks a lot for donating, I really appreciate the gesture 😀

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.