Forum
Facebook OG / Twitter Cards using variables
Hi,
I'm having issues implementing this solution: https://solutions.grabaperch.com/integrations/facebook-and-twitter-sharing
Adding content via the Page Details tab in the perch back end works fine. It's the passing of variables in the head that is not working.
I've basically copied and pasted the code from Rachel's example and get the following output:
<meta property="og:site_name" content="" />
<meta property="og:url" content="" />
<meta property="og:title" content="Home Page" />
<meta property="og:description" content="Rid your life of clutter with 'Declutter Me' the London based service that offers hands on practical help organising your life." />
<meta property="og:image" content="" />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="" />
<meta name="twitter:title" content="Home Page" />
<meta name="twitter:description" content="Rid your life of clutter with 'Declutter Me' the London based service that offers hands on practical help organising your life." />
<meta name="twitter:url" content="" />
The docs page: https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/
...states that variable can only be passed when using templates which are parsed at runtime – such as content rendered with perch_content_custom() rather than the precompiled output from perch_content().
Could this be the culprit as to why the variables are not appearing in the output?
Thanks
Here is the php code:
Perhaps try perch_page_attributes_extend :
Just tried that and it broke the site at that point in the output for some reason. Thanks though
It seems that using perch_page_attributes_extend at all breaks the page.
Any ideas why that would be?
Thanks :-)
Yes, not sure. Over to Drew and Rachel.
Like you, I was finding that PerchSystem::set_var wasn't passing any content into page attributes, but perch_page_attributes_extend worked for me.
Can you share the full code please simon?
Are you running 2.7.4?
2.7.3 so I'll upgrade and see
It wasn't for twitter card, but same principle I think.
I see that perch_page_attributes_extend is new to 2.7.4 - just backing up now ready to upgrade.
:-)
Updating perch has fixed it. Since perch_page_attributes_extend() wasn't a feature until 2.7.4 that explains it. Thanks for your helpful alternative Simon.
Great :)