Support > Elxis 4.x/5.x DEV

Is it possible to add meta tags to Frontpage ONLY?

(1/3) > >>

seadhna:
Hi, I am adding the facebook plugin to all articles, which brings in all the required OG META tags for each article very nicely.
But how can I add OG META tags to the Frontpage ONLY?
I tried adding to the index.php of the template, but this then over-writes the OG META for all pages.

seadhna:
I figured this out: components > com_content > controllers > fpage.php

I've added meta tag: $eDoc->addCustom('<meta property="og:image" content="url_of_image.jpg" />');

However, I'm struggling to add the description?

$eDoc->addCustom('<meta property="og:image" content="HOW DO I CALL THE METADESC HERE?" />');

seadhna:
$eDoc->addCustom('<meta property="og:description" content="HOW DO I CALL THE METADESC HERE?" />');

seadhna:
Hi again,
I've figured out the frontpage, but for articles with the FB like plugin, I am adding twitter tags. How do I change this line so it pulls the article description and not the site description?

Many thanks!
            $eDoc->addCustom('<meta property="twitter:description" content="'.$elxis->getConfig('METADESC').'"/>');

datahell:
The following lines of code can be placed anywhere, eg in your template's index.php file, in order to determine if you are in frontpage. Then you can set your meta tags for frontpage:

$elxuri = eFactory::getURI()->getElxisUri();
$elxis = eFactory::getElxis();
if (($elxuri == '') || ($elxuri == 'content:/') || ($elxuri == '/') || ($elxuri == 'content') || ($elxuri == $elxis->getConfig('DEFAULT_ROUTE'))) {
   //we are in frontpage
}

The proper way to handle article data is to develop a plugin. From the plugin you can access article's meta tags and set your custom meta data.

An alternative way is to use the constant Elxis generates to find the article you are and then query the database to get the information you need.
In article pages Elxis sets the constant ELXIS_ARTID with value of the article's ID.

Here is an example to set article's meta tag for twitter.
if (defined('ELXIS_ARTID')) {
   $db = eFactory::getDB();
   $sql = "SELECT ".$db->quoteId('subtitle')." FROM ".$db->quoteId('#__content')." WHERE ".$db->quoteId('id')." = :xid";
   $stmt = $db->prepareLimit($sql, 0, 1);
   $stmt->bindParam(':xid', ELXIS_ARTID, PDO::PARAM_INT);
   $stmt->execute();
   $metadesc = $stmt->fetchResult();
   if ($metadesc) {
      eFactory::getDocument()->addCustom('<meta property="twitter:description" content="'.$metadesc.'"/>');
   }
}

Code fixed, see below

Navigation

[0] Message Index

[#] Next page

Go to full version