Search code examples
phpjoomlajoomla3.0

Joomla add some meta tags one page


I have a page for job in my joomla and I want to add some tags to the header of this page, using controller but I never used joomla I don't know how

the tags are:

<meta property="og:title" content="link_title">
<meta property="og:url" content="page_url">
<meta property="og:description" content="page_description">

My controller is in

/home/ly/web/site/http/components/com_mks_career/controller.php

and my view is

/home/ly/web/site/http/templates/kms/html/com_mks_career/job/default.php

I found this code but I don't know where to call it and how to use it

$this->document->setMetaData( 'og:image', JURI::base().'imagename.jpg');          
$this->document->setMetaData( 'og:title' , $pagetitle );          
$this->document->setMetaData( 'og:description' , $item->metadesc );       
$this->document->setMetaData( 'og:url' , JURI::base().$_SERVER ['REQUEST_URI'] );         
$this->document->setMetaData( 'og:site_name' , $this->conf->get('config.sitename'));          
$this->document->setMetaData( 'og:type' , 'cat:type' );

Solution

  • Here's some untested code to get you started, you would add it to your page template, in the section where it builds up the head content of your page

    $doc = JFactory::getDocument();
    
    // Get ID of current page
    $id = JFactory::getApplication()->input->getInt('id');
    
    // Define your custom meta tags
    $link_title = "custom tag 1";
    $page_url = "custom tag 2";
    $page_description = "custom tag 3";
    
    
    // the ID of the page I wanted to customise
    if ($id == 123){
    
        // add your tags for for page ID=123 here
        $doc->setMetaData('og:title', $link_title);
        $doc->setMetaData('og:url', $page_url);
        $doc->setMetaData('og:description', $page_description);
    }
    

    I hope this helps!