Mautic Community Forums

Adding add facebook and twitter image meta tags dynamically in landing page

Just sharing one way to add facebook and twitter image meta tags dynamically in landing page:



Step 01) Add the code bellow in base.html.twig from theme.

Note: See in the end of article the meta tags for title and description too.

Quote:


Step 02: Create a folder called "LandingPages" in the Mautic FileManager

Step 03: Add the pictures [facebook] and [twitter] in the folder LandingPages with the follow structure.
Replace the XX for the LandingPage ID according to Mautic.
XX_banner_twitter.png
XX_banner_facebook.png

Additional information: Meta tags for title and description too.
Quote:






Just sharing one way to add facebook and twitter image meta tags dynamically in landing page:

Step 01) Add the code bellow in base.html.twig from theme.
Note: See in the end of article the meta tags for title and description too.

Step 02: Create a folder called “LandingPages” in the Mautic FileManager

Step 03: Add the pictures [facebook] and [twitter] in the folder LandingPages with the follow structure.
Replace the XX for the LandingPage ID according to Mautic.
XX_banner_twitter.png
XX_banner_facebook.png

Additional information: Meta tags for title and description too.

This is great!
However, it’s a little techy for the average person to understand.
Would it be possible to check if the files exist, and if not, to default to a logo file or something?
I can wrap my head around it in PHP, and partly in twig, but can’t figure out how to actually check if it exists correctly in twig.
Any ideas?
Thanks for sharing the excellent code, this should be a standard added to Mautic, right up there with UTM tags that did get implemented.

Did a little thinking. Got the simplest solution I think—do it via .htaccess at the server level!

Simply create a new .htaccess file in the folder where you store the Facebook and Twitter images.
In that file enter the following. And ta-da, your default image can be set on the last line.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ Default-Image.png [NC,L]