Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-04-05 10:49:01

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Hand-code social media share buttons

I’m currently using addThis for share buttons, but I want to get rid of the cruft and cookies it adds and I want to use my own icons. I’m looking for a simple way to code these buttons manually.

I found a nice method here Create manual social media share buttons but it relies on wordpress specific functions:

$url   = urlencode( get_permalink() );
$img   = urlencode( genesis_get_image( array( 'format' => 'url' ) ) );
$title = urlencode( get_the_title() );

I guess these could be done natively in PHP, but I don’t know any PHP.

I’d be very grateful for any help.

Offline

#2 2018-04-05 11:01:39

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Hand-code social media share buttons

Which social media channels specifically do you want to allow?

There’s many ways to achieve this, but the simplest would probably be the pat_article_social Textpattern plugin.

Offline

#3 2018-04-05 12:42:22

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Offline

#4 2018-04-05 13:42:40

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: Hand-code social media share buttons

A simple method, you can style it any way you want:

<a class="share-facebook" href="https://www.facebook.com/sharer/sharer.php?u=https://your-domain.com" title="Title text"><span>Facebook</span></a>
<a class="share-twitter" href="https://twitter.com/intent/tweet?text=predefined%20text&amp;url=https://your-domain.com" title="Title text"><span>Twitter</span></a>

Offline

#5 2018-04-05 15:08:37

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Hand-code social media share buttons

masa wrote #310647:

I guess these could be done natively in PHP, but I don’t know any PHP.

That is one of the advantages that Textpattern has always had over WordPress: You don’t need to know any PHP. This is the same block of code minus all the extra stuff that WP requires.

<a href="http://www.facebook.com/sharer/sharer.php?u=<txp:permlink />&t=<txp:title />" class="share-button facebook" target="_blank">Share on Facebook</a>
<a href="http://www.twitter.com/intent/tweet?url=<txp:permlink />&text=<txp:title />" class="share-button twitter" target="_blank">Tweet Me!</a>
<a href="http://pinterest.com/pin/create/button/?url=<txp:permlink />&media=<txp:image_url id='<txp:custom_field name="article_image" />' />&description=<txp:title />" class="share-button pinterest" target="_blank">Pinterest</a>
<a href="http://plus.google.com/share?url=<txp:permlink />" class="share-button google" target="_blank">Google+</a>
<a href="http://www.linkedin.com/shareArticle?mini=true&url=<txp:permlink />" class="share-button linkedin" target="_blank">LinkedIn</a>
<a href="http://www.reddit.com/submit?url=<txp:permlink />" class="share-button reddit" target="_blank">Reddit</a>

Offline

#6 2018-04-11 11:38:20

masa
Member
From: North Wales, UK
Registered: 2005-11-25
Posts: 1,095

Re: Hand-code social media share buttons

Great, thanks everyone for all the replies!

That is one of the advantages that Textpattern has always had over WordPress: You don’t need to know any PHP. This is the same block of code minus all the extra stuff that WP requires.

Yes, I remembered that :)

I think I’ll go with Michael’s solution as it’s short and very “Textpattern-ish”.

Offline

#7 2018-04-23 21:25:59

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

Re: Hand-code social media share buttons

Just adding to this, that Michael’s (edit: and GugUser’s) solution seems to be the only one, that doesn’t necessarily support the data mining done by all social media companies (survival strategy) – or does it still?

Last edited by jayrope (2018-04-23 21:27:45)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#8 2018-04-24 02:50:53

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Hand-code social media share buttons

jayrope wrote #311339:

or does it still?

Back in 1997 or so, a friend of mine and I put together what we considered at the time a massive list of Young Adult Literature Resources you could find on the Web. I put it online and submitted it to all the major search engines. And a few weeks later, it was very exciting that when you did a search the page would show up.

Flash forward to the early days of Blogging and it was simply amazing by 2002/2003 that you could post something online, have it spidered, indexed, and be able to search for it within a few hours.

Putting these buttons on a page is certainly a way to bring the content to the attention of the various sites. Is that data-mining? Possibly. I guess it depends on your point of view.

Offline

#9 2018-05-31 15:27:24

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

Re: Hand-code social media share buttons

Michael, hmm, it seems easier (and doesn’t involve visitor tracking) to simply submit a URL to various search engines and then let those do their work.


A hole turned upside down is a dome, when there’s also gravity.

Offline

#10 2018-05-31 16:26:36

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Hand-code social media share buttons

Revisiting this thread so as to contribute an alternative code, based on Michael’s but using more txp tags.

<a href="http://www.facebook.com/sharer/sharer.php?u=<txp:permlink />&amp;t=<txp:title />: <txp:meta_description format="" />" class="share-button facebook" target="_blank">Share on Facebook</a>
<a href="http://www.twitter.com/intent/tweet?url=<txp:permlink />&amp;text=<txp:title />: <txp:meta_description format="" />" class="share-button twitter" target="_blank">Tweet Me!</a>

You get my drift….


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#11 2018-05-31 17:49:29

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Hand-code social media share buttons

jayrope wrote #312221:

Michael, hmm, it seems easier (and doesn’t involve visitor tracking) to simply submit a URL to various search engines and then let those do their work.

In my redesign of Patetech, I figured out the easiest way in 4.7 to keep myself from being tracked so I don’t throw off the stats.

    <txp:if_logged_in not>
        <txp:output_form form="google-global-site-tag" />
        <txp:output_form form="google-auto-ad-code" />
    </txp:if_logged_in>

One of the things I am working on now is figuring out how to give site visitors the ability to do the same thing.

Offline

#12 2018-05-31 17:56:56

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Hand-code social media share buttons

michaelkpate wrote #312229:

In my redesign of Patetech, I figured out the easiest way in 4.7 to keep myself from being tracked so I don’t throw off the stats.

<txp:if_logged_in not>...

p. Nice omission of the else statement!!!

One of the things I am working on now is figuring out how to give site visitors the ability to do the same thing.

Would oui_cookie be able to do that?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB