WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Twitter Tweet coded into theme (5 posts)

  1. baszer
    Member
    Posted 2 years ago #

    Hello,

    on the twitter developers page you can find the following tweet button

    <script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
    <div>
       <a href="https://twitter.com/share" class="twitter-share-button"
          data-url="https://dev.twitter.com/pages/tweet_button"
          data-via="your_screen_name"
          data-text="Checking out this page about Tweet Buttons"
          data-related="anywhere:The Javascript API"
          data-count="vertical">Tweet</a>
    </div>

    Now I want to hardcode this into my theme. I thought it should work with the following code:

    <script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
    <div>
       <a href="https://twitter.com/share" class="twitter-share-button"
          data-url="<?php the_permalink(); ?>"
          data-text="<?php the_title(); ?>"
          data-count="vertical">Tweet</a>
    </div>

    Now the problem comes. The title shows up fine, but there is no URL what so ever. What do I do wrong?

    (the website is on a local server)

  2. Jeremy Herve
    Member
    Posted 2 years ago #

    I have just tested your code locally, it works fine for me.

    Where do you pleace that snippet of code in your theme?

  3. baszer
    Member
    Posted 2 years ago #

    @jeremy

    (the website is on a local server)

    this was making the error

    thanks for your answer.

    For anyone who wants to code the tweet this into his theme (with short permalink):

    <script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
    <div>
       <a href="https://twitter.com/share" class="twitter-share-button"
          data-url="<?php echo get_bloginfo('url')."/?p=".$post->ID; ?>"
          data-text="<?php the_title(); ?>"
          data-count="vertical">Tweet</a>
    </div>
  4. Jeremy Herve
    Member
    Posted 2 years ago #

    You can replace the_permalink by the_shortlink if you want, but I wouldn't worry too much about that if I were you : Twitter automatically shortens your links with their t.co URL shortener.

  5. baszer
    Member
    Posted 2 years ago #

    ow cool Jeremy, I also found another solution! ;)

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic