How to customize tweet text for blog post title, not page title

homebrewbargain
@homebrewbargain HomebrewBargains

I've got some tweet buttons on my site and they are using the page name in the text field of the tweet. This works on my secondary individual blog posts, where the title of the page changes to that of the blog post. But on the front page, the tweet buttons for each article will include the home page url, not the individual post title.

Is there a parameter to enter in data-text that will display the blog post title, not the main page's title and url? I've got a facebook like button which does perfectly fine, but the twitter isn't working.

1 year 35 weeks ago

Replies

bridgetbfarrell
@bridgetbfarrell Bridget Farrell

I'm having the same issue here? Has anyone solved this?? I'd so appreciate some help! :)

1 year 13 weeks ago
SMPowered
@SMPowered Patrick Cummings

If you're using a php based blog and editing your php code, try adding the data-text attribute and setting <?php the_title(); ?> as the value for the data-text attribute. I've also added the permalink to the blog post in the Tweet by including the permalink call as the attribute for data-url. Your theme may be slightly different int he way it handles the url and so, this code may or may not work for you.

like such:

  1. <a href="https://twitter.com/share" class="twitter-share-button" data-via="YOUR_TWITTER_ID_HERE" data-text="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-lang="en">Tweet</a>
  2. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
1 year 9 weeks ago
pankaj_jindal
@pankaj_jindal Pankaj Jindal

Any solutions to this yet for non php based blogs?

7 weeks 4 days ago
PrimoCreative
@PrimoCreative Primo

@SMPowered -

This is the exact functionality I've been looking for - for blog posts - however I'm trying to use my own custom Tweet button, as opposed to the twitter-share-button. Is there a simple solution here? The link works perfectly otherwise.

2 weeks 4 days ago