• Resolved wings69

    (@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

    etc.

    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

    ?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    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

    (@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 Hector Cabrera

    (@hcabrera)

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

    I am having the same issue but using an RSS Feed aggregator. I don’t want <div> and </div> showing up on my titles. Where exactly would I implement this section of code?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @davegee423,

    The code above is specific to this plugin so I’m not sure it’ll work for you: it removes certain words from post titles rendered by WordPress Popular Posts.

    If you want to remove <div> tags from an RSS feed and you have access to the site that generates said feed then you can use this filter hook to do so: the_title_rss.

    If you don’t have access to the site that generates the feed then you have to check whether your RSS aggregator provides a way to remove <div> tags from titles.

    If all of the above sounds a bit too technical for you, you may want to consider hiring a developer so they can help you with this stuff.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove certain words from title of posts?’ is closed to new replies.