• Hi there,

    I’m using IFTTT to pull in my Instagrams as blog posts. However, if I hashtag or use someone username in the post, it shows up on my blog and looks silly.

    Does anyone know of a function I can throw into functions.php to get rid of any words that include a # or an @ on the front of it?

    Here is an example:
    Went to the beach today. #sunshine #ocean @sally

    I’d like it to say:
    Went to the beach today.

    Is this doable? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You may use str_replace function to do that.

    Thread Starter brandmotu

    (@brandmotu)

    Can you give an example of how that would look? Thanks so much!

    Thread Starter brandmotu

    (@brandmotu)

    So I got it semi-working by sticking the following functions in functions.php:

    //Remove #'s on Instagram Posts
    function remove_hashtags_str($string){
        return str_replace('#', '',
            preg_replace('/(?:#[\w-]+\s*)+$/', '', $string));
    }
    add_filter('the_title', 'remove_hashtags_str');
    
    //Remove @'s on Instagram Posts
    function remove_usernames($string){
        return preg_replace('/@(?=[\w-]+)/', '',
            preg_replace('/(?:@[\w-]+\s*)+$/', '', $string));
    }
    add_filter('the_title', 'remove_usernames');

    My problem now is that anytime there is an apostrophe such as ‘, it’s trying to use &#39 but it’s actually turning it into &039.

    So I now have sentences like the following:

    I think it’s mine becomes: I think it&039;s mine.

    Any help? Thanks

    Kindly use this one,

    function remove_hashtags_str($string){
        return preg_replace('/(\#.*?)\s/', '', $string);
    }

    Thread Starter brandmotu

    (@brandmotu)

    Sorry thats not working.

    I think it’s mine

    is now:

    I think it&mine

    I cheeked, its working fine.

    kindly check the code.

    function remove_hashtags_str($string){
        return preg_replace('/(\#.*?)\s/', '', $string);
    }
    
    echo remove_hashtags_str("I think it's mine");
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Stripping (#) Hashtags and (@) usernames from Instagram in title’ is closed to new replies.