Dynamic Meta Tag Content

Three years later, is this still true?

Is what true? :slight_smile:

Facebook and Twitter still not reading dynamic meta tags?

I need to set the meta tags for Facebook linking so am checking if this is still the case that Facebook and Twitter cannot read dynamic content. What’s the technique for addressing this?

Facebook and Twitter require your og:tags to be rendered on the server side. If you are using nodejs, you can use server-side rendering for that.
For other server models, you will need to write custom code as server-side rendering is not available.

I have used the PHP code solution in this post effectively in the past.
Could proably do with a bit of an update to use $_ENV variables to hide the login credential which could be exposed on server error but the solution does work.

1 Like

Thanks Brian.

How do you reference the $_ENV vars in PHP? I’ve tried $_ENV['db_user'] but it’s empty.

Hmmm, try checking ‘variables_order’ setting in your PHP ini file and make sure the setting includes an "E’ to define creation of $_ENV vars
Also check the output of getenv() from PHP which should list all $_ENV variables

Thanks Brian. Before I get myself into ini files, etc. Can you confirm the syntax for accessing env variables which are created in the Environment section of the server connect settings?

I used this PHP solution and it worked a treat.
One thing that Facebook seems to need is the image dimensions, so I had to add code to manage presenting that info too.

1 Like

I believe you are correct, I confess I have never used ENV variables on php platform.
<?PHP echo getenv(); ?>
Would be my first port of call.
(That’s the first line of php I have written on about 2 years!)
Otherwise probably need assistance from the oracle @patrick

That outputs nothing so I’ll wait for Patrick’s wisdom. :+1:

My understanding is which globals are supported is defined in variables_order in the php.ini file.
If not defined (no E in string) then ENV variables are not created. Then again I am no expert on this and am unsure how wappler creates and manages ENV variables internally.

Thanks Brian. I’m unsure about the link between Wappler environment variables and PHP ones, too, so Patrick is the one for this.

It would be lovely for Wappler to add the same Server-Side rendering for PHP just like they have for NodeJS. Then all this would be native stuff.

1 Like

I love Wappler but this is a big downside. Its a pity there seems to be no way to do this other than to use NodeJS. We created a lot of stuff in our native .NET but had to rewrite it and adopt NodeJS instead - it was a great move however we still have a lot of .NET areas we’d like to keep so having native server side rendering of META tags would be the icing on the cake.

1 Like

Try this:

<?php print_r(getenv()); ?>

Thanks @Apple. This gives me loads of environment stuff but not any of the variables I set in the Environment section of the Server Connect Settings.

@patrick - if I’ve set an Environment variable in the SC settings, how can I access them in PHP on a page?

Ensure that code I gave you runs after the Wappler library include

If you confirm the above, open a bug report, sounds like PHP is not loading the environment variables set in Wappler configuration JSON. This JSON is read and the variables set in the environment

Thanks @Apple.

I put it right at the very end immediately before the tag and my env variables aren’t among all the output. I’ll open a bug report. I wanted to first establish how the Wappler env vars are used in case I was barking up the wrong tree.

Do you find the way to improve SEO un php?