Integrating Twitter with WordPress is pretty easy to do without a plugin. With a few lines of code you can have a nice tweet this or follow me button on every post or page of your WordPress website.

However, the URL that is part of the Tweet is the permalink URL and for many sites you’ll want to Tweet a shortened URL. If like me, using and Yoast’s Bitly Shortlink plugin, you maybe wondering how to get your short URL to be part of your tweet.

Joost kindly stores the bitty short URL in custom post meta field so all you have to do is retrieve it and show it on the page

<a href="" class="twitter-share-button" data-url="<?php echo get\_post\_meta($id, '\_yoast\_bitlylink', true); ?>" data-counturl=<?php echo get_permalink(); ?> data-count="horizontal" data-via="damiensaunders" rel="me">Tweet</a><script type="text/javascript" src="//"></script>


Yoast Shortlinks

Tags:, Social Media, Twitter, Yoast

Read more from my blog for an introduction and quick tips on developing in Hugo or UCTD.

Meet the author

Photo for Damien Saunders
Damien Saunders
An experienced management consultant and business leader interested in digital transformation, product centred design and scaled agile. If I'm not writing about living with UCTD (an autoimmune disease), I'm probably listening to music, reading a book or learning more about wine.