Advertisement

Meta tags of all content items appended to front page meta tag

General questions relating to Joomla! There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
User avatar
andreseso
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Jan 07, 2006 1:07 pm
Contact:

Meta tags of all content items appended to front page meta tag

Post by andreseso » Sat Apr 22, 2006 1:19 am

In my Web http://andreso.net the Meta Description and Meta Keywords tags are not functioning as I expected.  The Meta descriptions I have written for all content items are appended to the front page meta tag.  Each sentence is from a content item.

Code: Select all

<meta name="description" content="andreso.net -- Blog personal donde este individuo  cuenta muchas cosas que se salen de la rutina de sus días (sobre todo vacaciones) y alguna opinion y eventualmente algun articulo tecnico, En junio del 2005 fui con mi novia de vacaciones a Lanzarote, En setiembre del 2005 fui con mi novia de vacaciones a París, la ciudad de las luces.  El último día pille gripe., Estuve más de dos años detrás de un logopeda para aprender a pronunciar la erre, Tras tres meses de asistir media hora al día, cinco días a la semana a una logopeda aprendí a pronunciar la erre., He tenido muchas desgracias a lo largo de mi vida profesional con equipos electrónicos., Fui a Noruega al funeral de un tío mío.  Vi a mucha familia que no había visto en años.  Tristes circunstancias., El que familiares estén todo el tiempo al lado de su querido en un hospital es perjudicial., Operacion triunfo está basado en robar un poco de dinero a muchas personas., Pasé las navidades del 2005 en Montreal con mi familia, Mi Web le parece de muy poco interés a tanto Google como los demás buscadores, Impresiones de unas vacaciones en Tunez, Dando un paseo por la playa un gigoló tunecino se nos acercó., El Globalia Savana tiene empleados cuya única función es estafar a los huespedes." />
The Site wide meta tag is appended to a content item.  This is from http://andreso.net/vacaciones/una_excur ... tuita.html

Code: Select all

<meta name="description" content="andreso.net -- Blog personal donde este individuo cuenta muchas cosas que se salen de la rutina de sus días (sobre todo vacaciones) y alguna opinion y eventualmente algun articulo tecnico, El Globalia Savana tiene empleados cuya única función es estafar a los huespedes." />
This is not what I expected.  I would prefer only the sitewide description tag to apply to the front page and only the content item meta tag to apply to each content item.  I would like short meta tags. Fortunately only the meta tags of the content items shown on the front page are appended.  I see no way of configuring this option so I suppose it is by design.

Off topic, I really love Joomla.  I had been fighting with xoops for a couple of years and I still did not know how to use it.  I was not able to climb its learning curve.  After about a week with Joomla I was going full steam ahead.
I go faster forward when I stumble and I don't fall down. Falls hurt

Advertisement
User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by nibra » Sat Apr 22, 2006 2:45 am

You'll have to hack two files:

includes/frontend.php, function mosShowHead():

Code: Select all

 $mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
  //  disable global keywords
  //  $mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );
components/com_content/content.html.php, function show():

Code: Select all

   //  disable local description
    //  $mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
    $mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );
Regards
Niels

User avatar
andreseso
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Jan 07, 2006 1:07 pm
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by andreseso » Sat Apr 22, 2006 9:39 am

Thanks for the pointer but it does not work.

To includes/joomla.php I added

Code: Select all

        /**
        * @param string The value of the name attibute
        * @param string The value of the content attibute to append to the existing
        * Replaces the corresponding Meta Tag with the new contents
        */
        function replaceMetaTag( $name, $content ) {
                $name = trim( htmlspecialchars( $name ) );
                $n = count( $this->_head['meta'] );
                for ($i = 0; $i < $n; $i++) {
                        if ($this->_head['meta'][$i][0] == $name) {
                                $content = trim( htmlspecialchars( $content ) );
                                $this->_head['meta'][$i][1] = $content ;
                                return;
                        }
                }
                $this->addMetaTag( $name , $content );
        }
I replaced the corresponding section of components/com_content/content.html.php with

Code: Select all

               //$mainframe->appendMetaTag( 'description', $row->metadesc );
                //$mainframe->appendMetaTag( 'keywords', $row->metakey );
                $mainframe->replaceMetaTag( 'description', $row->metadesc );
                $mainframe->replaceMetaTag( 'keywords', $row->metakey );
and I replaced the corresponding section of mosShowHead() in includes/frontend.php with

Code: Select all

        //$mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
        //$mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );
        $mainframe->replaceMetaTag( 'description', $mosConfig_MetaDesc );
        $mainframe->replaceMetaTag( 'keywords', $mosConfig_MetaKeys );
The problem is that mosShowHead is called last and the meta description tag is always the one in my configuration file, even for the content items.  I need a way of knowing if I am in the front page (first item of the main menu) or viewing a content item to fine tune mosShowHead to only replace the meta tag in the front page

Thanks for pointing me in the right direction
I go faster forward when I stumble and I don't fall down. Falls hurt

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by nibra » Sat Apr 22, 2006 11:21 am

andreseso wrote: I need a way of knowing if I am in the front page (first item of the main menu) or viewing a content item to fine tune mosShowHead to only replace the meta tag in the front page
In short terms:

Code: Select all

if ($option == 'com_frontpage') {
    // .... On frontpage
} elseif ($option == 'com_content') {
    // ... On content
} else {
    // ... Anything else
}
Regards
Niels

User avatar
andreseso
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Jan 07, 2006 1:07 pm
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by andreseso » Sat Apr 22, 2006 12:44 pm

Thanks, that worked.  My includes/frontpage.php is now

Code: Select all

function mosShowHead() {
        global $database, $option, $my, $mainframe, $_VERSION;
        global $mosConfig_MetaDesc, $mosConfig_MetaKeys, $mosConfig_live_site, $
mosConfig_sef, $mosConfig_absolute_path, $mosConfig_sitename, $mosConfig_favicon
;

        $task = mosGetParam( $_REQUEST, 'task', '' );

        if ($my->id || $mainframe->get( 'joomlaJavascript' )) {
                ?>
                <script language="JavaScript" src="<?php echo $mosConfig_live_si
te;?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
                <?php
        }

        //$mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
        //$mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );
if ($option == 'com_frontpage') {
        $mainframe->replaceMetaTag( 'description', $mosConfig_MetaDesc );
        $mainframe->replaceMetaTag( 'keywords', $mosConfig_MetaKeys );
}
I go faster forward when I stumble and I don't fall down. Falls hurt

User avatar
andreseso
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Jan 07, 2006 1:07 pm
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by andreseso » Thu May 04, 2006 9:36 pm

I have been informed that I was not clear enough with providing explanations on how to have the frontpage with the site meta tags and the content pages with the content meta tags.

The changes are to add the following function in includes/joomla.php

Code: Select all

   /**
        * @param string The value of the name attibute
        * @param string The value of the content attibute to append to the existing
        * Replaces the corresponding Meta Tag with the new contents
        */
        function replaceMetaTag( $name, $content ) {
                $name = trim( htmlspecialchars( $name ) );
                $n = count( $this->_head['meta'] );
                for ($i = 0; $i < $n; $i++) {
                        if ($this->_head['meta'][$i][0] == $name) {
                                $content = trim( htmlspecialchars( $content ) );
                                $this->_head['meta'][$i][1] = $content ;
                                return;
                        }
                }
                $this->addMetaTag( $name , $content );
        }
in includes/frontend.php, inside the function mosShowHead you find the two lines below that append the comments
$mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
$mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );
[

These two lines you comment and below you paste the following code block

Code: Select all

  
if ($option == 'com_frontpage') {
        $mainframe->replaceMetaTag( 'description', $mosConfig_MetaDesc );
        $mainframe->replaceMetaTag( 'keywords', $mosConfig_MetaKeys );
}
The problem is that mosShowHead is called last and if we are not on the front page the content meta tags are overwritten with the site meta tags if it were not for the replacemetatag calls beeing inside of an if block

Final change.  This in components/com_content/content.html.php inside function show, do the following change

Code: Select all

               //$mainframe->appendMetaTag( 'description', $row->metadesc );
                //$mainframe->appendMetaTag( 'keywords', $row->metakey );
                $mainframe->replaceMetaTag( 'description', $row->metadesc );
                $mainframe->replaceMetaTag( 'keywords', $row->metakey );
I go faster forward when I stumble and I don't fall down. Falls hurt

BadBoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Tue Dec 06, 2005 12:45 pm

Re: Meta tags of all content items appended to front page meta tag

Post by BadBoy » Thu May 11, 2006 3:50 pm

Thanks andreseso and nibra.  That worked great for me!

Thought I found I didn't need the last change andresesso, it just works without making it.

aliakbari
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Apr 24, 2006 11:38 am

Re: Meta tags of all content items appended to front page meta tag

Post by aliakbari » Sat Sep 16, 2006 3:56 pm

Thanks andreseso. It worked for me too.

To all people that add this hack to their sites! You should define replaceMetaTag function right above the place where function appendMetaTag is defined.

Also in andresso's post there is a  [  character that is redundant and should not be inserted to codes.

Great job,
Ali
Last edited by aliakbari on Sat Sep 16, 2006 4:09 pm, edited 1 time in total.

User avatar
serrbiz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 231
Joined: Mon Sep 18, 2006 3:48 pm
Location: Dallas, TX
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by serrbiz » Mon Dec 11, 2006 11:04 pm

andreseso,

Works well.  Just a note to say when I modifed the /includes/joomla.php, I added the modification to at line 547.  It worked.  Prior to that I added near the footer and it didn't work.

M.

eezz
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Sat Sep 16, 2006 10:20 am
Contact:

Re: Meta tags of all content items appended to front page meta tag

Post by eezz » Tue Jan 30, 2007 11:44 am

Brilliant, exactly what I needed! This works a treat, great for SEO.  :)


Cheers,

Ian.

[MOD note: please do not include your URL in the message, use the signature instead, see Forum Rules: http://forum.joomla.org/index.php/topic,65.0.html - pe7er]
Last edited by pe7er on Wed Jan 31, 2007 2:46 pm, edited 1 time in total.
http://www.performingartsnews.com
Connect to the Performing Arts

g-c
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sun Feb 11, 2007 2:34 pm

Re: Meta tags of all content items appended to front page meta tag

Post by g-c » Mon Feb 26, 2007 8:00 pm

Yes, works very good!!! a topic like this needs to be sticky or needs to implemented in FAQ's or Joomla-Tips i think.

Regards, Christian

Advertisement

Locked

Return to “General Questions - 1.0.x”