Forum

Thread tagged as: Question

Social Media sharing links

How can I put a social share link to a specific page and not only to the homepage? What do I have to add to the path?

<a href="<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A//www..domain.com">Share on Facebook</a>

Thanks!

Martin Stettler

Martin Stettler 0 points

  • 4 years ago
Simon Clay

Simon Clay 127 points

Hi Martin,

I think you might be able to do it like this:

<a href="<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A//www..domain.com/<?php $Perch->get_page(); ?>">Share on Facebook</a>

Hi Simon

Unfortunately it does not work. Beside some errors in the code when I try this:

<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A//www.domain.com/<?php $Perch->get_page(); ?>">Share on Facebook</a>

I get this error message:

Fatal error: Call to a member function get_page() on null in domain.com/perch/templates/pages/project.php

Thank you for your much appreciated help! Martin

Drew McLellan

Drew McLellan 2638 points
Perch Support

You would need:

echo PerchSystem::get_page();

Great it works! One more thing: any idea what I should to the code add that FB's output is equal to the description tag of the page?

Thank you!

Drew McLellan

Drew McLellan 2638 points
Perch Support

The description from the page attributes?

Yes, I thought this would be easier than any text out from the content?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I have tried to put both variables, but it does not output both, I see instead the landing page description only. Can you please have a look at my code?

<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A//www.domain.com/<?php echo PerchSystem::get_page(); echo perch_page_attribute('description'); ?>">Share on Facebook</a>

Thank you, Drew!

Drew McLellan

Drew McLellan 2638 points
Perch Support

echo perch_page_attribute('description');

only needs to be

perch_page_attribute('description');

What output do you get?

If I do so

<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A//www.domain.com/<?php echo PerchSystem::get_page(); perch_page_attribute('description'); ?>">Share on Facebook</a>

I get the title and description of the landing page. If I just put get_page I get the correct page but as text an conditional comment (<!--[if lte IE 8]>...<![endif]-->) that I had inside the header. I deleted it but can't get it away and so the correct description is not displayed. Please try yourself and look what you get: https://dev.nordland.dieweberei.ch/kmar.php

Many thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you doing to output the description in the head of the page? It doesn't seem like this should be so hard.

Right, shouldn't be difficult...

I use this for the description

<?php perch_page_attributes(); ?>

as you see in the header the output is correct:

<meta name="description" content="..." />
Drew McLellan

Drew McLellan 2638 points
Perch Support

So are you saying that this outputs nothing?

perch_page_attribute('description');

No, no. I get the correct description tag in the page header. But it is not used for the facebook share...

Drew McLellan

Drew McLellan 2638 points
Perch Support

So what does that line output?

For some reason the conditional comment was making the problems. It's now working. Thanks!