FORUMS
LATEST THREADS

Translate Sngine og-image Tutorial

0
11كيلو بايت
Translate Sngine og-image Tutorial

Translate Sngine og-image Tutorial

The og-image is an essential part of your social media previews. In Sngine, it is possible to dynamically translate the og-image file name based on the active language. This tutorial will guide you through the process of modifying the page_header function to support translated og-image filenames.

Step 1: Locate the page_header Function

Open the file includes/functions.php and locate the page_header function. It should look like this:

function page_header($title, $description = '', $image = '')
{
    global $smarty, $system;
    $description = ($description != '') ? $description : __($system['system_description']);
    if ($image == '') {
        if ($system['system_ogimage']) {
            $image = $system['system_uploads'] . '/' . $system['system_ogimage'];
        } else {
            $image = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/og-image.jpg';
        }
    }
    $smarty->assign('page_title', $title);
    $smarty->assign('page_description', $description);
    $smarty->assign('page_image', $image);
}
    

Step 2: Modify the page_header Function

Update the function to support translation for the og-image. Replace the existing code with the following:

function page_header($title, $description = '', $image = '')
{
    global $smarty, $system;
    $description = ($description != '') ? $description : __($system['system_description']);

    /**
     * TRANSLATE IMAGE
     */
    if ($image == '') {
        if (!empty($system['system_ogimage'])) {
            $image = $system['system_uploads'] . '/' . $system['system_ogimage'];
        } else {
            // Get the translated base name
            $image_base_name = __("og-image");

            // Append the file extension
            $image = $system['system_url'] . '/content/themes/' . $system['theme'] . '/images/' . $image_base_name . '.jpg';
        }
    }
    /**
     * END TRANSLATE IMAGE
     */

    $smarty->assign('page_title', $title);
    $smarty->assign('page_description', $description);
    $smarty->assign('page_image', $image);
}
    

Step 3: Add the og-image Translation

To add the translation for og-image, edit the language file in your project. For example, in the Spanish language file, add the following:

msgid "og-image"
msgstr "og-image-es"
    

For other languages, replace og-image-es with the appropriate filename, such as og-image-PT for Portuguese.

Step 4: Upload Translated Images

Ensure that you upload the images files with the correct names to the following directory:

/content/themes/{theme_name}/images/
    

For example:

  • og-image-es.jpg for Spanish
  • og-image-PT.jpg for Portuguese

Step 5: Test Your Changes

Visit your website, switch between different languages, and check the social media previews. The correct og-image file should load based on the active language.

Note: If the og-image is not displaying correctly, ensure the language file and image filenames are correctly configured.

By following this tutorial, you can ensure that your website’s social media previews reflect the active language, providing a localized experience for your users. This approach enhances engagement and creates a more professional impression.

Like
1
إعلان مُمول
البحث
الأقسام
إقرأ المزيد
سنجن
PageFeeds Pro with SocialSync for Sngine
PageFeeds Pro with SocialSync for Sngine is the ultimate solution for enhancing your Sngine...
بواسطة Jane Marcia 2025-01-22 03:53:13 16 12كيلو بايت
Marketing
Email Going to Spam Folder? Here’s How to Fix It with DKIM and DMARC
If your emails are consistently landing in the email spam folder, the culprit is often improper...
بواسطة Jane Marcia 2024-12-20 07:01:27 0 10كيلو بايت
Networking
Cutting-Edge E-commerce Solutions - Expand Your Business Online
In today’s digital marketplace, a strong online presence is essential for any business that...
بواسطة Jane Marcia 2025-02-15 09:47:53 7 3كيلو بايت
سنجن
Sngine Free 404 Hack: Why a User-Friendly 404 Page is a Must for Your Website
 A poorly designed 404 page can frustrate users, cause them to abandon your site, and even...
بواسطة Jane Marcia 2024-12-19 03:41:15 2 10كيلو بايت
سنجن
Why Integrating Cloudflare DNS, CDN, and CAPTCHA is a Game-Changer for Sngine Sites
Running a social network like Sngine comes with its own set of challenges. High traffic, security...
بواسطة Jane Marcia 2025-01-14 15:45:53 0 8كيلو بايت