4.875 1 1 1 1 1 1 1 1 1 1 Rating 4.88 (4 Votes)

Попытка разработчиков в Джумле 3 решить проблему с атрибутом rel="canonical" окончилась фиаско.

Поэтому, сделаем возможность прописать rel="canonical" для каждого материала.

 

В джумле существует куча полей которые я никогда не прописываю, но которые могут выводить информацию в мета тегах, это:

<meta name="rights" content="авторские права" />
<meta name="author" content="автор" />
<meta name="xreference" content="внешняя ссылка" />
<meta name="keywords" content="ключи">

Я решил использовать одно из ненужных полей для вывода ссылки на каноническую страницу:

<link rel="canonical" href="/" />

Мой выбор пал на мета-тег keywords, потому что он есть во всех внешних компонентах (особено меня интересова JoomGallery).

Итак, для того что бы сделать настраиваемый и управляемый рел каноникал нужно открыть файл head.php, находящийся по адресу:

/libraries/joomla/document/html/renderer

Найти вот такой код:

// Generate META tags (needs to happen as early as possible in the head)
		foreach ($document->_metaTags as $type => $tag)
		{
			foreach ($tag as $name => $content)
			{
				if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type'))
				{
					$buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
				}
				elseif ($type == 'standard' && !empty($content))
				{
					$buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
				}
			}
		}




И заменить на этот:

// Generate META tags (needs to happen as early as possible in the head)
		foreach ($document->_metaTags as $type => $tag)
		{
			foreach ($tag as $name => $content)
			{
				if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type'))
				{
					$buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
				}
				elseif ($type == 'standard' && !empty($content))
				{
//canonical
                if ($content) {
                if ($name=='keywords') {
                $buffer .= $tab . '<link rel="canonical" href="' . htmlspecialchars($content) . '" />' . $lnEnd; 
                continue;
                }
					$buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
					}
				}
			}
		}




Теперь, если нужен любой рел-каноникал, мне достаточно прописать его в поле «Мета-тег Keywords».

P.S. Метод так же работает в Joomla 2.5

P. P.S. При обновлении Джумлы файл head.php, обновиться. Поэтому сделайте дубль и после замените его.

Сказать спасибо лучше кнопками:

Комментарии   

0 #24 Elmer 13.07.2018 20:25
Hі! Do youu usе Twitter? І'd like tо follow youu iff that wkuld be ok.

I'm undoubteԁly еnjoʏing your blog ɑnd loⲟk forward to new posts.


my blog: poсket knives online: https://schweizerknive.dk/10-ting-man-kan-med-en-lommekniv/
Цитировать
0 #23 Florentina 10.07.2018 19:09
It's wonderful that you are getting ideas from this article as well ass from
our dialogue made at this time.

My webpage: scrapbook sequin glitter: https://www.etsy.com/listing/611837399/16-antique-real-gold-scratched-papers-12
Цитировать
0 #22 Rachelle 09.07.2018 11:02
I was curious if you ever thought of changing the layout off your blog?
Its very weol written; I love what youce got to say.
But maybe you could a little more in the way of content so people could connect with it better.

Youve got an awful lot of text for ony having 1 or 2 pictures.
Maybe yyou could space it out better?

my homepage: Betsey: https://www.etsy.com/listing/597112150/42-antique-gold-glitter-and-sequin
Цитировать
0 #21 Kaley 08.07.2018 13:49
It's going to be end of mkne day, except beforre ending I am reading this wondeerful article to improve my know-how.


Here is my web page - digital paper pack: https://www.etsy.com/listing/602368280/16-antique-gold-glitter-plaid-tartan
Цитировать
0 #20 Ernesto 04.07.2018 09:31
I am extremely impressed with your writing skills and
also with the layout on your weblog. Is this a paid theme or did you
customize it yourself? Eiter way keep up tthe nice quality writing, it's rare
to see a great blog like this one these days.

Feeel freee too visit my web blog :: digital paper pack: https://www.etsy.com/listing/595984486/42-pink-bokeh-papers-12-inch-300-dpi
Цитировать
0 #19 Alexis 02.07.2018 22:43
Excellent read, I jjust assed this onto a friend who was diing some research on that.

And he jjust bought me lunch since I found it for him smile Therefore llet me rephrase that: Thank you for lunch!


Feel free to viisit my site ... scrapbook sequin glitter: https://www.etsy.com/listing/602329310/16-luxury-gold-and-pink-glitter-plaid
Цитировать
0 #18 Monty 02.07.2018 17:23
I was curious if you ever thhought of changing the layoutt of your website?
Its very well written; I love what youve got to say. But maybe youu could a little more in the way of content so people could connect with it
better. Youve got an awful lot of text for only having 1 or
two pictures. Maybe you could space it out better?

Here is my blog ... Antique gold glitter: https://www.etsy.com/listing/576055674/gold-glitter-motivation
Цитировать
0 #17 Margherita 01.07.2018 12:27
Hello to all, hhow is all, I think every one is getting more from this
site, and your views are pleasant designed for new users.


Check out my blog post - luxury
background: https://www.etsy.com/listing/594392104/42-mint-foil-papers-12-inch-300-dpi
Цитировать
0 #16 Indira 30.06.2018 00:36
I am extremely imporessed with your writing skills as well as with the lahout oon your blog.
Is this a paid theme oor diid you modify it yourself?
Either way keep up the nice quality writing, it's rare
too see a great blog like ths one these days.

my web page: digital gold sequin paper: https://www.etsy.com/listing/598035290/42-antique-gold-satin-silk-cloth-papers
Цитировать
0 #15 Annie 21.06.2018 15:07
Nice read, I just passed this onto a colleague who waas doiing a little
research on that. And he just bought me lujch because I found it
for him smile Therefore let me rephrase that: Thank you for lunch!


Look at my web-site :: old sequin kit: https://www.etsy.com/listing/609186231/42-gold-glitter-papers-12-inch-300-dpi
Цитировать

Добавить комментарий


Защитный код
Обновить

Feedburner
Поиск
Новые материалы
Последнии Комментарии