Q&A

meta태그를 걸때 og태그가 아닌 일반 메타태그에도 property가 걸리는걸 name로 바꾸고

 

name=author 항목을 추가하는 게 목적인데

 

(한마디로 meta add 애드온 기능을 합치는 겁니다)

 

우선 잘 작동은 하는데요

 

모듈이나 php에 대해서는 하나도 모르다 보니 제대로 적용된건지 모르겠네요

 

 

 

seo.controller.php에서 //Open Graph 위쪽 항목을

 

$this->addMeta_name('keywords', $piece->keywords);
$this->addMeta_name('description', $piece->description);
$this->addMeta_name('author', $piece->author);

 

이렇게 추가/변경하고 (원래는 addMeta 라고 되어 있었고 마지막줄은 없었습니다)

 

seo.class.php를 이렇게 변경시켰습니다 (강조되어 있는 부분이 제가 추가한 부분입니다)

 

class seo extends ModuleObject
{
public $SEO = array(
'link' => array(),
'meta' => array(),
'metaname' => array()
);

protected $canonical_url;

private $triggers = array(
array('display', 'seo', 'controller', 'triggerBeforeDisplay', 'before')
);

public function getConfig()
{
$oModuleModel = getModel('module');
$config = $oModuleModel->getModuleConfig('seo');
if (!$config) $config = new stdClass;
if (!$config->use_optimize_title) $config->use_optimize_title = 'N';
if (!$config->ga_except_admin) $config->ga_except_admin = 'N';
if (!$config->ga_track_subdomain) $config->ga_track_subdomain = 'N';
if ($config->site_image) 
{
$config->site_image_url = Context::get('request_uri') . 'files/attach/site_image/' . $config->site_image;
}

return $config;
}

public function addMeta($property, $content)
{
if (!$content) return;

$oModuleController = getController('module');
$oModuleController->replaceDefinedLangCode($content);
if (!in_array($property, array('og:url'))) {
$content = htmlspecialchars($content);
$content = str_replace(PHP_EOL, ' ', $content);
}

$this->SEO['meta'][] = array('property' => $property, 'content' => $content);
}

public function addMeta_name($name, $content)
{
if (!$content) return;

$oModuleController = getController('module');
$oModuleController->replaceDefinedLangCode($content);

$this->SEO['metaname'][] = array('name' => $name, 'content' => $content);
}

public function addLink($rel, $href)
{
if (!$href) return;

$this->SEO['link'][] = array('rel' => $rel, 'href' => $href);
}

protected function applySEO()
{
$config = $this->getConfig();
$logged_info = Context::get('logged_info');

foreach ($this->SEO as $type => $list) {
if (!$list || !count($list)) continue;

foreach ($list as $val) {
if ($type == 'meta') {
Context::addHtmlHeader('<meta property="' . $val['property'] . '" content="' . $val['content'] . '" />');
} elseif ($type == 'metaname') {
Context::addHtmlHeader('<meta name="' . $val['name'] . '" content="' . $val['content'] . '" />');
} elseif ($type == 'link') {
Context::addHtmlHeader('<link rel="' . $val['rel'] . '" href="' . $val['href'] . '" />');
}
}
}

 

 

이거 이렇게 하는게 맞는건가요?

 

(특히 49~50 저거 필요한 건지 모르겠습니다. 어떤 걸 의미하는 건지도 모르겠고...)

 

아시는 분 계시면 확인좀 부탁드립니다

댓글 4

  • 근데 코드 하이라이터는 원래 등록하고 나면 일렬로 변해버리나요? 미리보기 할때는 탭키 입력된게 적용되어 있는데 등록하면 그게 전부 없어져버리는데 어떻게 할 수가 없네요
  • @기븐
    웹에서는 탭키를 재대로 인식 하지 못하기 때문입니다.
  • 차후 SEO 모듈 신 버젼에서는 해당 버그가 해결되네요.

    author는 빠진거 같습니다만...

    https://github.com/xpressengine/xe-module-seo/commit/2e9711293d49568d3da7cfd2e2c286e3fc9a4a6c

  • @불금
    이 글보다 훨씬 나을거 같네요