The Joomla! Forum ™



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.



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sat Apr 22, 2006 1:19 am 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Sat Jan 07, 2006 1:07 pm
Posts: 62
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:
<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:
<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.

_________________
Caminante no hay camino, se hace camino al andar. Al echar la vista atrás se ve la senda que nunca se ha de volver a pisar. Golpe a golpe, verso a verso.
If I stumble and do not fall, I advance
http://andreso.net
http://megustafumar.org


Top
 Profile  
 
PostPosted: Sat Apr 22, 2006 2:45 am 
User avatar
Joomla! Guru
Joomla! Guru
Offline

Joined: Wed Nov 16, 2005 2:02 am
Posts: 588
Location: Breklum - Nordfriesland
You'll have to hack two files:

includes/frontend.php, function mosShowHead():
Code:
 $mainframe->appendMetaTag( 'description', $mosConfig_MetaDesc );
  //  disable global keywords
  //  $mainframe->appendMetaTag( 'keywords', $mosConfig_MetaKeys );


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


Regards
Niels


Top
 Profile  
 
PostPosted: Sat Apr 22, 2006 9:39 am 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Sat Jan 07, 2006 1:07 pm
Posts: 62
Thanks for the pointer but it does not work.

To includes/joomla.php I added
Code:
        /**
        * @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:
               //$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:
        //$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

_________________
Caminante no hay camino, se hace camino al andar. Al echar la vista atrás se ve la senda que nunca se ha de volver a pisar. Golpe a golpe, verso a verso.
If I stumble and do not fall, I advance
http://andreso.net
http://megustafumar.org


Top
 Profile  
 
PostPosted: Sat Apr 22, 2006 11:21 am 
User avatar
Joomla! Guru
Joomla! Guru
Offline

Joined: Wed Nov 16, 2005 2:02 am
Posts: 588
Location: Breklum - Nordfriesland
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:
if ($option == 'com_frontpage') {
    // .... On frontpage
} elseif ($option == 'com_content') {
    // ... On content
} else {
    // ... Anything else
}


Regards
Niels


Top
 Profile  
 
PostPosted: Sat Apr 22, 2006 12:44 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Sat Jan 07, 2006 1:07 pm
Posts: 62
Thanks, that worked.  My includes/frontpage.php is now
Code:
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 );
}

_________________
Caminante no hay camino, se hace camino al andar. Al echar la vista atrás se ve la senda que nunca se ha de volver a pisar. Golpe a golpe, verso a verso.
If I stumble and do not fall, I advance
http://andreso.net
http://megustafumar.org


Top
 Profile  
 
PostPosted: Thu May 04, 2006 9:36 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Sat Jan 07, 2006 1:07 pm
Posts: 62
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:
   /**
        * @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:
 
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:
               //$mainframe->appendMetaTag( 'description', $row->metadesc );
                //$mainframe->appendMetaTag( 'keywords', $row->metakey );
                $mainframe->replaceMetaTag( 'description', $row->metadesc );
                $mainframe->replaceMetaTag( 'keywords', $row->metakey );

_________________
Caminante no hay camino, se hace camino al andar. Al echar la vista atrás se ve la senda que nunca se ha de volver a pisar. Golpe a golpe, verso a verso.
If I stumble and do not fall, I advance
http://andreso.net
http://megustafumar.org


Top
 Profile  
 
PostPosted: Thu May 11, 2006 3:50 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Dec 06, 2005 12:45 pm
Posts: 33
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.


Top
 Profile  
 
PostPosted: Sat Sep 16, 2006 3:56 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Apr 24, 2006 11:38 am
Posts: 20
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.

Top
 Profile  
 
PostPosted: Mon Dec 11, 2006 11:04 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Mon Sep 18, 2006 3:48 pm
Posts: 210
Location: Ridgefield, Connecticut (NYC)
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.

_________________
Signature forum rules: viewtopic.php?f=8&t=65


Top
 Profile  
 
PostPosted: Tue Jan 30, 2007 11:44 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Sep 16, 2006 10:20 am
Posts: 8
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]

_________________
http://www.performingartsnews.com
Connect to the Performing Arts


Last edited by pe7er on Wed Jan 31, 2007 2:46 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Feb 26, 2007 8:00 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Sun Feb 11, 2007 2:34 pm
Posts: 87
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 



Who is online

Users browsing this forum: aerolux and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group