Move most meta tags above the <title> to below it #2419

This commit is contained in:
Kijin Sung 2024-10-27 22:50:02 +09:00
parent bf3d920a1d
commit bf0093b56a
4 changed files with 31 additions and 24 deletions

View file

@ -2879,14 +2879,10 @@ class Context
{
return isset(self::$_instance->meta_tags[$name]) ? self::$_instance->meta_tags[$name]['content'] : null;
}
$ret = array();
foreach(self::$_instance->meta_tags as $name => $content)
else
{
$ret[] = array('name' => $name, 'is_http_equiv' => $content['is_http_equiv'], 'content' => escape($content['content'], false));
return array_values(self::$_instance->meta_tags);
}
return $ret;
}
/**
@ -2894,14 +2890,17 @@ class Context
*
* @param string $name name of meta tag
* @param string $content content of meta tag
* @param mixed $is_http_equiv value of http_equiv
* @param bool $is_http_equiv
* @param bool $is_before_title
* @return void
*/
public static function addMetaTag($name, $content, $is_http_equiv = false)
public static function addMetaTag($name, $content, $is_http_equiv = false, $is_before_title = true)
{
self::$_instance->meta_tags[$name] = array(
'name' => $name,
'content' => escape(self::replaceUserLang($content, true), false),
'is_http_equiv' => (bool)$is_http_equiv,
'content' => self::replaceUserLang($content, true),
'is_before_title' => (bool)$is_before_title,
);
}

View file

@ -506,7 +506,7 @@ class HTMLDisplayHandler
$description = Context::getMetaTag('description');
}
Context::addOpenGraphData('og:description', $description);
Context::addMetaTag('description', $description);
Context::addMetaTag('description', $description, false, false);
}
// Add metadata about this page.
@ -641,7 +641,7 @@ class HTMLDisplayHandler
{
if ($tag !== '')
{
Context::addOpenGraphData('og:article:tag', $tag, false);
Context::addOpenGraphData('og:article:tag', $tag);
}
}
@ -663,7 +663,7 @@ class HTMLDisplayHandler
// Add author name for articles.
if ($page_type === 'article' && $permitted && config('seo.og_use_nick_name'))
{
Context::addMetaTag('author', $oDocument->getNickName());
Context::addMetaTag('author', $oDocument->getNickName(), false, false);
Context::addOpenGraphData('og:article:author', $oDocument->getNickName());
}
@ -683,21 +683,21 @@ class HTMLDisplayHandler
function _addTwitterMetadata()
{
$card_type = $this->_image_type === 'document' ? 'summary_large_image' : 'summary';
Context::addMetaTag('twitter:card', $card_type);
Context::addMetaTag('twitter:card', $card_type, false, false);
foreach(Context::getOpenGraphData() as $val)
{
if ($val['property'] === 'og:title')
{
Context::addMetaTag('twitter:title', $val['content']);
Context::addMetaTag('twitter:title', $val['content'], false, false);
}
if ($val['property'] === 'og:description')
{
Context::addMetaTag('twitter:description', $val['content']);
Context::addMetaTag('twitter:description', $val['content'], false, false);
}
if ($val['property'] === 'og:image' && $this->_image_type === 'document')
{
Context::addMetaTag('twitter:image', $val['content']);
Context::addMetaTag('twitter:image', $val['content'], false, false);
}
}
}

View file

@ -693,7 +693,8 @@ class ModuleHandler extends Handler
}
}
if ($kind === 'admin') {
if ($kind === 'admin')
{
Context::addMetaTag('robots', 'noindex');
}
@ -865,29 +866,29 @@ class ModuleHandler extends Handler
$module_config = ModuleModel::getModuleConfig('module');
if (!empty($module_info->meta_keywords))
{
Context::addMetaTag('keywords', $module_info->meta_keywords);
Context::addMetaTag('keywords', $module_info->meta_keywords, false, false);
}
elseif (!empty($site_module_info->settings->meta_keywords))
{
Context::addMetaTag('keywords', $site_module_info->settings->meta_keywords);
Context::addMetaTag('keywords', $site_module_info->settings->meta_keywords, false, false);
}
elseif (!empty($module_config->meta_keywords))
{
Context::addMetaTag('keywords', $module_config->meta_keywords);
Context::addMetaTag('keywords', $module_config->meta_keywords, false, false);
}
// Set meta description.
if (!empty($module_info->meta_description))
{
Context::addMetaTag('description', $module_info->meta_description);
Context::addMetaTag('description', $module_info->meta_description, false, false);
}
elseif (!empty($site_module_info->settings->meta_description))
{
Context::addMetaTag('description', $site_module_info->settings->meta_description);
Context::addMetaTag('description', $site_module_info->settings->meta_description, false, false);
}
elseif (!empty($module_config->meta_description))
{
Context::addMetaTag('description', $module_config->meta_description);
Context::addMetaTag('description', $module_config->meta_description, false, false);
}
}