Search code examples
browserjoomla2.5titleforum

Kunena - how to change Site name in browser page


Hello I am using Kunena 3.0.4 and I want to change my forum titles in the browser page.

Now they are

Category Index- Forum Name- site name or topic name-forum name-site name

And I want to make them

Topic name-site name

Where can I change this? Thank you in advance


Solution

  • I was trying to debug this exact same issue and I found your post. Luckily, I figured out how to do this with some head scratching, Googling and searching the Kunena source files. So here is an answer, in case you haven't already figured it out.

    There are two things that need to be done: Editing the setTitle() function and editing the language file for the Kunena component. The function can be found in the view.php file present in the following folder for Kunena 3.0.5 (the latest version as of May 21, 2014):

    YOUR_ROOT_DIR/public_html/libraries/kunena/view.php
    

    Then, edit the function setTitle() to your heart's content. Play around with it to give you the look and feel you are going for. Here is the default function:

    public function setTitle($title) {
        if (!$this->state->get('embedded')) {
            // Check for empty title and add site name if param is set
            $title = strip_tags($title);
            if ($this->app->getCfg('sitename_pagetitles', 0) == 1) {
                $title = JText::sprintf('JPAGETITLE', $this->app->getCfg('sitename'), $this->config->board_title .' - '. $title);
            } elseif ($this->app->getCfg('sitename_pagetitles', 0) == 2) {
                $title = JText::sprintf('JPAGETITLE', $title .' - '. $this->config->board_title, $this->app->getCfg('sitename'));
            } else {
                // TODO: allow translations/overrides (also above)
                $title = KunenaFactory::getConfig()->board_title .' :: '. $title;
            }
            $this->document->setTitle($title);
        }
    }
    

    Now, the lines that need to be edited are in the if-elseif-else clause. Notice the hypen '-', being added via concatenation. For me, I had to edit the elseif part. The sprintf function needs two arguments apart from the 'JPAGETITLE'. The first argument here is $title .' - '. $this->config->board_title which is the title variable plus the forum title as set in Kunena. The second argument is $this->app->getCfg('sitename'), which is your site name. There will be an additional hypen between argument 1 and 2. So if we have the following scenario:

    $title = 'Random Page';
    $this->config->board_title = 'Kunena Forums';
    $this->app->getCfg('sitename') = 'Joomla Site';
    

    You will get the output, based on this code:

    Random Page - Kunena Forums - Joomla Site
    

    I have instead modified this function to:

    public function setTitle($title) {
        if (!$this->state->get('embedded')) {
            // Check for empty title and add site name if param is set
            $title = strip_tags($title);
            if ($this->app->getCfg('sitename_pagetitles', 0) == 1) {
                $title = JText::sprintf('JPAGETITLE', $this->app->getCfg('sitename'), $this->config->board_title, $title);
            } elseif ($this->app->getCfg('sitename_pagetitles', 0) == 2) {
                $title = JText::sprintf('JPAGETITLE',  $title, $this->config->board_title);//, $this->app->getCfg('sitename'));
            } else {
                // TODO: allow translations/overrides (also above)
                $title = KunenaFactory::getConfig()->board_title .' :: '. $title;
            }
            $this->document->setTitle($title);
        }
    }
    

    So, the same example will give me:

    Random Page - Kunena Forums
    

    Further, you can change the default text that shows up on the Index page of the forums, i.e. "Category Index" to something nicer. To do that, you need to edit the language file at:

    YOUR_ROOT_DIR/public_html/components/com_kunena/language/en-GB/en-GB.com_kunena.views.ini
    

    Here, look for the tags:

    COM_KUNENA_VIEW_CATEGORY_DEFAULT="Topics in %s"    
    COM_KUNENA_VIEW_TOPICS_DEFAULT="Topic: %s"    
    COM_KUNENA_VIEW_CATEGORIES_DEFAULT="Category Index"
    

    Change the text to something better. For instance, I totally removed "Topic:" and "Topics in" and replaced "Category Index" with "Forums Home". So, now on my forums main page, I see

    Forums Home - My Website Forums
    

    Edit other strings in the language file to your liking and play around with the setTitle function.

    In your case, as you want to remove the forum name, remove the $this->config->board_title part in the sprintf.