Removing spaces from tag for social share

Hey All

I’d like to include my primary tag as a hashtag for Twitter and Facebook shares. Obviously, if I just use {{primary_tag.name}} in the URL string it’ll come out as #Getting Started (with a space between getting and started) instead of #GettingStarted. How do I remove the spaces from the URL string?

Matt

You should do the entire social share part from javascript and then append the code.
If you use ghost API to get primary_tag name then you can easily remove the white spaces from the tag. That would be much easier process.

If you want to hire an expert for custom ghost development-related work you may feel free contact us.

Hi @themeix

Thanks for the reply. Is it possible to point me in the direction of the code or tutorial?

Thanks

Matt

https://ghost.org/docs/api/v2/content/

These would help you.

1 Like

@themeix

Thanks for the info. This doesn’t really help with the process of putting the code together.

I understand you want to sell your services, but perhaps you can do this elsewhere?

I’ll await someone willing to share the code.

Thanks

Matt

You Can Use

{{primary_tag.slug}}
1 Like

You misunderstood me. if i really wants to sell the service only then i never shared any ref. url to you.

Btw i just set up a fresh ghost and then prepare the code for you. I hope its good to go. But definitely you need some idea about javascript to implement that.

api.posts
    .browse({limit: 1, include: 'tags'})
    .then((posts) => {
        posts.forEach((post) => {
		var post_tag_name = post.primary_tag.name ;
        console.log( post_tag_name.replace( /\s/g, '') ); 
        });
    })
    .catch((err) => {
        console.error(err);
    });

Output Resut

Ref : https://ghost.org/docs/api/v2/javascript/content/

1 Like