Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Twitter Follow Button

I'm attempting to embed a Twitter Follow button (https://twitter.com/about/resources/buttons#follow) onto a site that I write for, and I'm testing it in the Inspect Element to see if it will show up. However, whenever I add it in, only the embed code appears, not the button.

Help please!

1 Answer

Alex Hedley
Alex Hedley
16,381 Points

Could you add a link to the page or is it a local site? Another option would be to link a codepen or similar of the code you're using.

Is it showing this code instead of an image on your site?

<a href="https://twitter.com/AlexHedley" class="twitter-follow-button" data-show-count="false">Follow @AlexHedley</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>

This is what I'm using, and what shows up on the page instead of the link:

http://codepen.io/anon/pen/gLJqK

I don't have access to alter the actual HTML code (I don't run the site), but I'm being asked to see if I can make the "Follow Me" button appear.

Alex Hedley
Alex Hedley
16,381 Points

Do you know anyone who can make changes to the page? Just ask them to add that code in the place they need it on the page.

If you are just viewing the page you can inspect any element on the page, but this is read only, you would need access to the file server and make amendments to the source file for it to show for everyone else.

Yeah, but how would that work if there are multiple people writing for the site? Each person would want their specific Twitter account next to their byline, but the embed code is specific to one person....

Is your site supposed to look like it does?

Alex Hedley
Alex Hedley
16,381 Points

You would need to get the dev to create a way of doing this. Who controls the byline? What is the site written in? PHP, Ruby ...

<a href="https://twitter.com/AlexHedley" class="twitter-follow-button" data-show-count="false">Follow @AlexHedley</a>

There is my name mentioned twice <a href="https://twitter.com/AlexHedley" ...>Follow @AlexHedley</a>

Are the writers stored in a db, you could add another field to the writer of Twitter ID. Now the twitter embed code could be dynamically written to the page using this value to create the specific button.

Re: your db question - I will certainly find out and let you know.

Thanks for the help so far Alex.

How would I add another field for the writer ID? How would you code that?

Alex Hedley
Alex Hedley
16,381 Points

That depends on what db the site is using. Do you have admin access to the site/db etc. It would also require some coding on the article pages.

Nick Pettit
Nick Pettit
Treehouse Teacher

Tom,

It sounds like you're pasting the Twitter follow button code into a textbox in some kind of admin interface. You'll need to be able to actually edit the HTML to add the button. For example, if you were to paste that same code here, it would be cleaned and not actually rendered by the browser. Instead, it would just display the code. For example:

<a href="https://twitter.com/MattBHQ" class="twitter-follow-button" data-show-count="false">Follow @MattBHQ</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>