Sharethis facebook

I have a strong suspicion this is where the difference is. I've already tried using PHP but that didn't work. It would make sense as I understand stackpath will basically serve up a static page?

I'm setting up stackpath now. Fingers crossed.


Done and off to setup routing while waiting for the DNS changes to propogate.

Good idea! Thanks.

Paul, that's not going to work. PHP code is executed on the server side, while JavaScript code is rendered on the front end, on page load.

I don't think Facebook can render JavaScript in the meta tags as Google does.

1 Like

Nope I can not seem to get the php to parse the JavaScript for you in the head section, will continue looking.

I got the routing set up but that didn’t change anything. Stackpath is still saying the domain is still not pointing to stackpath so I’ll wait and see if that helps.

Learned routing though, so that’s a win!!

Yup, just found this out the hard way, but happy you confirmed it, so im not just doing it wrong, it's not meant to work, hahaha

1 Like

If that fails too, because StackPath can be horrid to get setup just right then this service is literally made to get around our particular issue Heather

https://prerender.io/

1 Like

The facebook scraper doesn’t support javascript, it just reads the html source. While all modern search engines support javascript based sites, social networks like facebook and twitter don’t.

The only way to have dynamic data in the meta tags for facebook is by using server-side rendering. You could use php to generate the content or a service like prerender.io as @psweb mentioned.

I’m implementing this functionality on a different part of my site so thought I would go ahead and put the solution here. It’s actually pretty simple. :slight_smile:

In php tags at the top of your page…

$tripbit_id = $_GET['tripbit_id'];

$json = file_get_contents('path/to/your/serverconnect?tripbit_id=' . $tripbit_id);

$data = json_decode($json, true);

$params['title'] = $data["query"]["title"];
$params['image'] =  $data["query"]["img"];
$params['description'] = $data["query"]["description"];
$params['url'] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

And then in your head tags…

        <meta property="og:url" content="<?php echo $params['url']; ?>" />

        <meta property="og:type" content="website" />

        <meta property="og:locale" content="en_US" />

        <meta property="og:title" content="<?php echo $params['title']; ?>" />

        <meta property="og:image" content="<?php echo $params['image']; ?>" />

        <meta property="og:description" content="<?php echo $params['description']; ?>" />

HTH…

5 Likes

Cool! Someone did the same for asp.net?

Absolutely brilliant Heather. Thanks for that. I’ve tweaked accordingly and it’s working perfectly.

A quick note to anyone else using this. The description field, if it’s in HTML format (like mine is) then you should use the strip_tags formatter in your API script and maybe truncate it, too:

querySocialMeta.iiBody.stripTags().trunc(250, true, '...')

Awesome tip. Thanks!

1 Like

@George Does this will be solved with the new PHP features you are planning to add on Wappler 7? php server side rendering?

Hello I am trying this but I get :

file_get_contents(/dmxConnect/api/propertyDetail.php?property_slung=xxx-huatulco-5b2): failed to open stream: No such file or directory.

Any idea?

Can you show a screenshot of this step inside your server action so we can see the path, and can you make sure a file with the right filename exists on the server at the path it is trying to access.

Captura de Pantalla 2024-10-07 a la(s) 12.20.00

Here is .

I’m away at the moment. Can have a look next week if you’ve not worked it out by then.

To get work I use the URL with domain instead of only path.

Sorry this screenshot does not really help, can i see inside that server action, all the steps as well as the properties you have set in the particular step that is causing the error?
I do however think that file_get_contents(/dmxConnect/api/propertyDetail.php?property_slung=xxx-huatulco-5b2) should look more like
file_get_contents(/api/propertyDetail.php?property_slung=xxx-huatulco-5b2)

I think is inside the dmxConnect folder, but cant get work.

If you add as a Server Connect action looks like this

 <dmx-serverconnect id="propDetails" url="/dmxConnect/api/propertyDetail.php" dmx-param:property_slung="query.property_slung" onsuccess="loadSlider()" dmx-on:unauthorized="propReditect.goto('/huatulco-rentals')"></dmx-serverconnect>

And works, so I dont understand why file_get_contents dont work...