Title: Need help coding a Twitter share button
Last modified: August 21, 2016

---

# Need help coding a Twitter share button

 *  Resolved [_alexsmith1](https://wordpress.org/support/users/_alexsmith1/)
 * (@_alexsmith1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/)
 * Hello all,
 * I need a bit of help creating a Twitter share button for my site. The one I’m
   using via the coding found on Twitter’s dev page ([https://dev.twitter.com/docs/tweet-button](https://dev.twitter.com/docs/tweet-button))
   is very close to what I need, but with one issue: it’s using the page’s title
   rather than the post’s. The page title includes the name of my site as a prefix“
   The Original Society | [Post Title]”. I want the text of the tweet to be in the
   format: [Post Title] [url] [via @origsociety1] instead of what I have now: [Page
   Title] [url] [via @origsociety1] using a share button with a vertical count box
   above. The code I’m using now is listed below, please help me adjust it as needed,
   thanks.
 * Also, here’s a link to a post on my site: [http://theoriginalsociety.com/eric-bellinger-i-dont-want-her-feat-problem-music-video/](http://theoriginalsociety.com/eric-bellinger-i-dont-want-her-feat-problem-music-video/)
   please scroll towards the bottom of the post and click the tweet button to see
   its current behavior.
 *     ```
       <div class='twitter-share share-widget'>
       							<a href="https://twitter.com/share" class="twitter-share-button" data-via="origsociety1" data-lang="en" data-count="vertical">Tweet</a>
       <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
       						</div>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/#post-4488384)
 * AFAICT you just add a “text” attribute to override the default title behavior.
   Then end of the link line should be like this:
    `data-count="vertical" text="
   <?php the_title() ?>">Tweet</a>`
 * The PHP `the_title()` inserts the current post title. It must be inside the “
   Loop”. The entire content-single.php template should be inside the Loop, which
   is where I assume you’re inserting this button. If my assumptions are wrong we
   may need to do something else.
 * I’m also assuming the URL and via user are coming from elsewhere and concatenated
   to this title by other means, we don’t need to do this as part of “text”.
 *  Thread Starter [_alexsmith1](https://wordpress.org/support/users/_alexsmith1/)
 * (@_alexsmith1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/#post-4488387)
 * Thanks for your help. I had already marked this as resolved because after I setup
   SEO titles this issue ended up working itself out. Hopefully your response helps
   someone else, though.
 *  Thread Starter [_alexsmith1](https://wordpress.org/support/users/_alexsmith1/)
 * (@_alexsmith1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/#post-4488390)
 * Actually, I still need help. I’d like my SEO title to contain my site’s name,
   which is what I’ve set it to do, so now the original issue has come up again.
   I need the code for the tweet button to be modded to grab the WordPress post 
   title rather than the SEO title. The above suggestion did not do anything, the
   tweet button still grabs the SEO title instead of the post title.
 *  Thread Starter [_alexsmith1](https://wordpress.org/support/users/_alexsmith1/)
 * (@_alexsmith1)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/#post-4488391)
 * I found the answer myself on a Twitter dev support thread. Here’s the code that
   makes the Twitter button grab the WordPress title:
 *     ```
       <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>
       <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>
       ```
   
 * I just need to make this a vertical button with count box and I’ll be set.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Need help coding a Twitter share button’ is closed to new replies.

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [dev](https://wordpress.org/support/topic-tag/dev/)
 * [social](https://wordpress.org/support/topic-tag/social/)
 * [twitter](https://wordpress.org/support/topic-tag/twitter/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [_alexsmith1](https://wordpress.org/support/users/_alexsmith1/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/need-help-coding-a-twitter-share-button/#post-4488391)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
