I am trying to set the page title, meta description and meta keywords to improve SEO on a ChronoForms v4 page by adding a Custom Code action in the On Load section:

  if ($form->data['LongTitle']) {
    $document = JFactory::getDocument();
  if ($form->data['MetaDescription']) {
    $document = JFactory::getDocument();
  if ($form->data['MetaKeywords']) {
    $document = JFactory::getDocument();
    $document->setMetaData('keywords', $form->data['MetaKeywords']);

setDescription and setMetaData work fine but setTitle does not work.

As per https://stackoverflow.com/a/31458607/1983389, it appears the article or menu option may set the page title later than the ChronoForm especially when loading the ChronoForm via the ChronoForms content plugin (as is the case in this example).

Tried adding a Meta Tager (sic) action in the On Load Section

The Meta Tager option has the same issue where the Meta Description and Meta Keywords are set OK but not the Page Title.

Tried changing the order of the content plugins

I tried moving the ChronoForms content plugin last but this didn't help.

Tried using Regular Labs Sourcerer to add code into the article

I tried adding the code directly into the article but this didn't work:

    $tour = JRequest::getVar('Tour');
    $db = JFactory::getDBO();
    $db->setQuery("SELECT cf_id,LongTitle FROM #__chronoforms_data_Tours WHERE cf_id='$tour'");
    $result = $db->loadObject();
    $tourname = $result->LongTitle;
    if ($tourname) {
      $document = JFactory::getDocument();
  • For the record, the sql in the setQuery doesn't look terribly stable/secure to me. And loadResult() seems like a better way to pull a single value from the row. Commented Aug 26, 2019 at 12:28

2 Answers 2


JavaScript to the rescue

The Page Title can be set via JavaScript as per https://stackoverflow.com/a/24881134

In ChronoForms, add a "Load JS" action to the "On Load" section with the following code:

window.onload=function() {
  changeTitle ('<?php echo $form->data['LongTitle']; ?>')
function changeTitle (newTitle) {

This works and apparently Google does crawl content injected by JavaScript.

Other search engines may not see JavaScript injected content so this is probably not the best practice and this method is only recommended where there is no better way to update the Page Title.

I'd be delighted to see some better answers than this poor work around.


You can modify:


and add before line

$output = new JoomlaGCLoader2('front', 'chronoforms6', 'chronoforms', $chronoforms6_setup);

$doc = JFactory::getDocument();

$app = JFactory::getApplication();
$menu = $app->getMenu()->getActive()->id;
if ( $app->getMenu()->getActive()->params->get('menu-meta_description') != ''){
if ( $app->getMenu()->getActive()->params->get('menu-meta_keywords') != ''){
    $doc->setMetadata('keywords', $app->getMenu()->getActive()->params->get('menu-meta_keywords'));


  • I don't know if your advice is sound, but you might like to DRY you code like this: 3v4l.org/oAr8n Commented Aug 26, 2019 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.