WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ
・descriptionをTraitへ ・トップとカスタム投稿アーカイブのOGPイメージ登録対応 ・OGP_URLのリンク修正(canonicalは不要のため削除) ・site_name、type、title、urlの設定 ・デフォルトのdescriptionの設定 ・meta keywordds/description 設定の変数、メソッド整理
This commit is contained in:
@@ -89,5 +89,18 @@ if (!class_exists('MTEE')) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ogp_img($type, $subtype = '') {
|
||||
if (empty($subtype)) {
|
||||
$id = get_option('_mtee')[$type]['ogp_img'];
|
||||
} else {
|
||||
$id = get_option('_mtee')[$type][$subtype]['ogp_img'];
|
||||
}
|
||||
if (!empty($id)) {
|
||||
return '<img src="' . wp_get_attachment_image_src($id, 'thumbnail')[0] . '">';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,15 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
if (!class_exists('mtee_meta_output_keydesc')) {
|
||||
|
||||
include MTEE_TRAIT_DIR . 'mtee_meta_desc_trait.php';
|
||||
|
||||
class mtee_meta_output_keydesc {
|
||||
|
||||
use mtee_meta_desc_trait;
|
||||
|
||||
private $site_name;
|
||||
private $description;
|
||||
private $metas = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->site_name = get_bloginfo('name');
|
||||
@@ -17,11 +22,12 @@ if (!class_exists('mtee_meta_output_keydesc')) {
|
||||
add_action('wp_head', array($this, 'post_output_add_metas'));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// meta keywords & meta description
|
||||
//--------------------------------------------------------------------
|
||||
public function post_output_add_metas() {
|
||||
$metas = array();
|
||||
$this->create_post_output_add_metas();
|
||||
echo implode(PHP_EOL, $this->metas) . PHP_EOL;
|
||||
}
|
||||
|
||||
public function create_post_output_add_metas() {
|
||||
if (is_home() || is_front_page()) {
|
||||
$type = 'top_page';
|
||||
} elseif (is_post_type_archive()) {
|
||||
@@ -36,12 +42,11 @@ if (!class_exists('mtee_meta_output_keydesc')) {
|
||||
$type = 'post_tag';
|
||||
}
|
||||
if (isset($type)) {
|
||||
$metas = $this->post_output_view_metas($type);
|
||||
$this->metas = $this->post_output_view_metas($type);
|
||||
}
|
||||
if (count($metas) == 0) {
|
||||
$metas = $this->create_default_keywords_description();
|
||||
if (count($this->metas) == 0) {
|
||||
$this->metas = $this->create_default_keywords_description();
|
||||
}
|
||||
echo implode(PHP_EOL, $metas) . PHP_EOL;
|
||||
}
|
||||
|
||||
public function post_output_view_metas($type): array {
|
||||
@@ -51,81 +56,38 @@ if (!class_exists('mtee_meta_output_keydesc')) {
|
||||
} elseif (isset($targets['taxonomies']) && array_key_exists($type, $targets['taxonomies'])) {
|
||||
$type = 'custom_tax';
|
||||
}
|
||||
|
||||
$meta_data = $this->post_output_get_meta_data($type);
|
||||
$meta_data = array(
|
||||
MTEE_NAME_KEYWORDS => str_replace('、', ',', $this->post_output_get_meta_keywords($type)),
|
||||
MTEE_NAME_DESCRIPTION => $this->post_output_get_meta_desc($type),
|
||||
);
|
||||
return $this->create_meta_tags($meta_data);
|
||||
}
|
||||
|
||||
public function post_output_get_meta_data($type): array {
|
||||
public function post_output_get_meta_keywords($type) {
|
||||
global $post;
|
||||
if ($type == 'top_page') {
|
||||
$meta_key_words = get_option('_mtee')['top_page']['keywords'];
|
||||
$meta_description = get_option('_mtee')['top_page']['description'];
|
||||
} elseif ($type == 'custom_post_archive') {
|
||||
$custom_post_name = get_post_type_object(get_post_type())->name;
|
||||
$meta_key_words = get_option('_mtee')['custom_post'][$custom_post_name]['keywords'];
|
||||
$meta_description = get_option('_mtee')['custom_post'][$custom_post_name]['description'];
|
||||
} elseif ($type == 'custom_tax' || $type == 'category' || $type == 'post_tag') {
|
||||
$queried_object = get_queried_object();
|
||||
$meta_key_words = get_term_meta($queried_object->term_id, MTEE_NAME_KEYWORDS, true);
|
||||
$meta_description = get_term_meta($queried_object->term_id, MTEE_NAME_DESCRIPTION, true);
|
||||
} else {
|
||||
$meta_key_words = get_post_meta($post->ID, MTEE_NAME_KEYWORDS, true);
|
||||
$meta_description = get_post_meta($post->ID, MTEE_NAME_DESCRIPTION, true);
|
||||
}
|
||||
|
||||
return array(
|
||||
MTEE_NAME_KEYWORDS => str_replace('、', ',', $meta_key_words),
|
||||
MTEE_NAME_DESCRIPTION => $meta_description,
|
||||
);
|
||||
return $meta_key_words;
|
||||
}
|
||||
|
||||
public function create_default_keywords_description(): array {
|
||||
$keywords = $this->create_default_keywords();
|
||||
$this->create_default_description();
|
||||
$this->description .= $this->create_default_description();
|
||||
$meta_data = array(
|
||||
MTEE_NAME_KEYWORDS => implode(',', $keywords),
|
||||
MTEE_NAME_KEYWORDS => implode(',', $this->create_default_keywords()),
|
||||
MTEE_NAME_DESCRIPTION => $this->description,
|
||||
);
|
||||
|
||||
return $this->create_meta_tags($meta_data);
|
||||
}
|
||||
|
||||
public function create_default_description() {
|
||||
$type = '';
|
||||
$title = '';
|
||||
$suffix_text = MTEE_META_DESC_ARCHIVE_BASE;
|
||||
|
||||
if (is_home() || is_front_page()) { //ページ
|
||||
$this->description .= MTEE_META_DESC_TOP_BASE;
|
||||
return;
|
||||
} elseif (is_page() || is_single()) { //ページ
|
||||
$type = 'page';
|
||||
$title = get_the_title();
|
||||
$suffix_text = MTEE_META_DESC_SINGLE_BASE;
|
||||
} elseif (is_category()) { //カテゴリー
|
||||
$type = 'category';
|
||||
$title = single_cat_title('', false);
|
||||
} elseif (is_tag()) { //タグ
|
||||
$type = 'tag';
|
||||
$title = single_tag_title('', false);
|
||||
} elseif (is_tax()) { //タクソノミー
|
||||
$type = 'tax';
|
||||
$title = single_term_title('', false);
|
||||
} elseif (is_post_type_archive()) { //カスタム投稿のアーカイブ
|
||||
$type = 'custom_post';
|
||||
$title = post_type_archive_title('', false);
|
||||
}
|
||||
|
||||
$replacement = $this->cnv_custom_template($type, $title, $suffix_text);
|
||||
|
||||
if (isset($replacement['org'])) {
|
||||
$search = array('<###>', '<%%%>');
|
||||
$description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>';
|
||||
$this->description .= str_replace($search, $replacement['org'], $description_noun);
|
||||
}
|
||||
}
|
||||
|
||||
public function create_default_keywords(): array {
|
||||
$type = '';
|
||||
$title = '';
|
||||
@@ -253,21 +215,5 @@ if (!class_exists('mtee_meta_output_keydesc')) {
|
||||
return $metas;
|
||||
}
|
||||
|
||||
public function cnv_custom_template($type, $title, $suffix_text) {
|
||||
if ($type == 'custom_post') {
|
||||
return array('org' => array(post_type_archive_title('', false), $suffix_text));
|
||||
}
|
||||
|
||||
$template = get_option('_mtee')['description_tmp'];
|
||||
if (isset($template[$type]) && !empty($template[$type])) {
|
||||
$search = array('##title##', '##site_name##', '##site_description##');
|
||||
$replacement = array($title, get_bloginfo('name'), get_bloginfo('description'));
|
||||
$this->description = str_replace($search, $replacement, $template[$type]);
|
||||
} else {
|
||||
return array('org' => array($title, $suffix_text));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,22 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
if (!class_exists('mtee_meta_output_ogp')) {
|
||||
|
||||
|
||||
class mtee_meta_output_ogp {
|
||||
|
||||
use mtee_meta_desc_trait;
|
||||
|
||||
public $site_name;
|
||||
public $ogp_type;
|
||||
public $ogp_description;
|
||||
public $ogp_title;
|
||||
public $ogp_url;
|
||||
public $ogp_img;
|
||||
|
||||
public function __construct() {
|
||||
$this->site_name = get_bloginfo('name');
|
||||
//GOPのプレフィックスを出力する
|
||||
add_filter('language_attributes', array($this, 'add_html_ogp_prefix'));
|
||||
add_action('wp_head', array($this, 'create_ogp_tag'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,5 +37,204 @@ if (!class_exists('mtee_meta_output_ogp')) {
|
||||
private function create_ogp_prefix(): string {
|
||||
return ' prefix="og: https://ogp.me/ns#"';
|
||||
}
|
||||
|
||||
public function create_ogp_tag() {
|
||||
$this->create_ogp_type();
|
||||
$this->create_ogp_title();
|
||||
$this->create_ogp_description();
|
||||
$this->create_ogp_image();
|
||||
$this->create_ogp_url();
|
||||
echo $this->set_ogp_tag();
|
||||
}
|
||||
|
||||
|
||||
public function set_ogp_tag() {
|
||||
$tags = '<meta property="og:title" content="' . $this->ogp_title . '" />' . PHP_EOL;
|
||||
$tags .= '<meta property="og:description" content="' . $this->ogp_description . '" />' . PHP_EOL;
|
||||
$tags .= '<meta property="og:type" content="' . $this->ogp_type . '" />' . PHP_EOL;
|
||||
$tags .= '<meta property="og:url" content="' . $this->ogp_url . '" />' . PHP_EOL;
|
||||
// $tags .= '<meta property="og:image" content="' . $this->ogp_img . '" />' . PHP_EOL;
|
||||
$tags .= '<meta property="og:site_name" content="' . $this->site_name . '" />' . PHP_EOL;
|
||||
// $tags .= '<meta name="twitter:card" content="summary_large_image" />' . PHP_EOL;
|
||||
// $tags .= '<meta name="twitter:site" content="ツイッターのアカウント名" />' . PHP_EOL;
|
||||
$tags .= '<meta property="og:locale" content="' . $this->get_ogp_locale() . '" />' . "\n";
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function get_ogp_locale(): string {
|
||||
$locale = get_locale();
|
||||
if (strlen($locale) == 2) {
|
||||
if ($locale === "ja")
|
||||
return "ja_JP";
|
||||
else
|
||||
return strtolower($locale) . '_' . strtoupper($locale);
|
||||
}
|
||||
}
|
||||
|
||||
public function create_ogp_type() {
|
||||
if (is_home() || is_front_page()) {
|
||||
$this->ogp_type = 'website';
|
||||
} else {
|
||||
$this->ogp_type = 'article';
|
||||
}
|
||||
}
|
||||
|
||||
public function create_ogp_title() {
|
||||
if (is_category()) {
|
||||
$this->ogp_title = single_cat_title('', false);
|
||||
} elseif (is_tag()) {
|
||||
$this->ogp_title = single_cat_title('', false);
|
||||
} elseif (is_tax()) {
|
||||
$this->ogp_title = single_term_title('', false);
|
||||
} elseif (is_post_type_archive()) {
|
||||
$this->ogp_title = post_type_archive_title('', false);
|
||||
} elseif (is_single() || is_page()) {
|
||||
$this->ogp_title = get_the_title();
|
||||
} elseif (is_home() || is_front_page()) {
|
||||
$this->ogp_title = $this->site_name;
|
||||
}
|
||||
}
|
||||
|
||||
public function create_ogp_description() {
|
||||
$this->ogp_description = $this->site_name . MTEE_META_DESC_PARTICLE;
|
||||
$this->ogp_description .= $this->set_ogp_description();
|
||||
}
|
||||
|
||||
public function set_ogp_description() {
|
||||
$type = '';
|
||||
$ogp_desc = '';
|
||||
|
||||
if (is_home() || is_front_page()) {
|
||||
$type = 'top_page';
|
||||
} elseif (is_post_type_archive()) {
|
||||
$type = 'custom_post_archive';
|
||||
} elseif (is_tax()) {
|
||||
$type = get_queried_object()->taxonomy;
|
||||
} elseif (is_page() || is_single()) {
|
||||
$type = get_post_type();
|
||||
} elseif (is_category()) {
|
||||
$type = 'category';
|
||||
} elseif (is_tag()) {
|
||||
$type = 'post_tag';
|
||||
}
|
||||
|
||||
$targets = get_option('_mtee');
|
||||
if (isset($targets['custom_posts']) && array_key_exists($type, $targets['custom_posts'])) {
|
||||
$type = 'custom_post';
|
||||
} elseif (isset($targets['taxonomies']) && array_key_exists($type, $targets['taxonomies'])) {
|
||||
$type = 'custom_tax';
|
||||
}
|
||||
|
||||
if (!empty($type)) {
|
||||
$ogp_desc = $this->post_output_get_meta_desc($type);
|
||||
}
|
||||
|
||||
if (empty($ogp_desc)) {
|
||||
$ogp_desc = $this->create_default_description();
|
||||
}
|
||||
return $ogp_desc;
|
||||
}
|
||||
|
||||
|
||||
public function create_ogp_url() {
|
||||
global $post;
|
||||
if (is_category()) {
|
||||
$this->ogp_url = get_category_link(get_query_var('cat'));
|
||||
} elseif (is_tag()) {
|
||||
$this->ogp_url = get_tag_link(get_query_var('tag_id'));
|
||||
} elseif (is_tax()) {
|
||||
$this->ogp_url = get_term_link((int)get_queried_object()->term_id);
|
||||
} elseif (is_post_type_archive()) {
|
||||
$custom_post_name = get_post_type_object(get_post_type())->name;
|
||||
$this->ogp_url = get_post_type_archive_link($custom_post_name);
|
||||
} elseif (is_single() || is_page()) {
|
||||
$this->ogp_url = get_permalink($post->ID);
|
||||
global $page, $paged;
|
||||
if ($paged >= 2 || $page >= 2) {
|
||||
$this->ogp_url .= 'page/' . max($paged, $page) . '/';
|
||||
}
|
||||
} elseif (is_home() || is_front_page()) {
|
||||
$this->ogp_url = get_bloginfo('url');
|
||||
}
|
||||
}
|
||||
|
||||
public function create_ogp_image() {
|
||||
global $post;
|
||||
$id = '';
|
||||
$type = '';
|
||||
if (is_post_type_archive()) {
|
||||
$type = 'custom_post_archive';
|
||||
} elseif (is_category()) {
|
||||
$id = get_query_var('cat');
|
||||
$type = 'cat';
|
||||
} elseif (is_tag()) {
|
||||
$id = get_query_var('tag_id');
|
||||
$type = 'tag';
|
||||
} elseif (is_tax()) {
|
||||
$id = get_queried_object()->term_id;
|
||||
$type = 'tax';
|
||||
} elseif (is_home() || is_front_page()) {
|
||||
$type = 'top_page';
|
||||
} elseif (is_page() || is_single()) {
|
||||
$id = $post->ID;
|
||||
$type = 'posts';
|
||||
}
|
||||
return $this->get_ogp_tag_img($id, $type);
|
||||
}
|
||||
|
||||
public function get_ogp_tag_img($id, $type) {
|
||||
if ($type == 'top_page') {
|
||||
$canonical = $this->set_top_page_ogp_img();
|
||||
} elseif ($type == 'custom_post_archive') {
|
||||
$canonical = $this->set_custom_post_archive_ogp_img();
|
||||
} elseif ($type == 'posts') {
|
||||
$canonical = $this->set_post_ogp_img($id);
|
||||
} elseif ($type == 'cat') {
|
||||
$canonical = $this->set_category_ogp_img($id);
|
||||
} elseif ($type == 'tag') {
|
||||
$canonical = $this->set_tag_ogp_img($id);
|
||||
} elseif ($type == 'tax') {
|
||||
$canonical = $this->set_tax_ogp_img($id);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_top_page_ogp_img() {
|
||||
$img = get_option('_mtee')['top_page']['ogp_img'];
|
||||
if (empty($img)) {
|
||||
$img = '';
|
||||
}
|
||||
return $img;
|
||||
}
|
||||
|
||||
public function set_custom_post_archive_ogp_img() {
|
||||
$custom_post_name = get_post_type_object(get_post_type())->name;
|
||||
$img = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_img'];
|
||||
if (empty($img)) {
|
||||
$img = '';
|
||||
}
|
||||
return $img;
|
||||
}
|
||||
|
||||
public function set_post_ogp_img($id) {
|
||||
$img = get_post_meta($id, MTEE_OGP_IMG, true);
|
||||
|
||||
}
|
||||
|
||||
public function set_category_ogp_img($id) {
|
||||
$img = get_term_meta($id, MTEE_OGP_IMG, true);
|
||||
|
||||
}
|
||||
|
||||
public function set_tag_ogp_img($id) {
|
||||
$img = get_term_meta($id, MTEE_OGP_IMG, true);
|
||||
|
||||
}
|
||||
|
||||
public function set_tax_ogp_img($id) {
|
||||
$img = get_term_meta($id, MTEE_OGP_IMG, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ placeholder="' . $this->set_default_ogp_desc() . '"/>
|
||||
<input class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="' . get_post_meta($post->ID, MTEE_OGP_IMG, true) . '" />
|
||||
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
|
||||
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
|
||||
<div id="ogp_media">' . $this->set_ogp_thumb($post->ID) . '</div>
|
||||
<div class="ogp_media">' . $this->set_ogp_thumb($post->ID) . '</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
@@ -65,7 +65,7 @@ image<br>
|
||||
<input class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="" />
|
||||
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
|
||||
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
|
||||
<div id="ogp_media"></div>
|
||||
<div class="ogp_media"></div>
|
||||
<script>
|
||||
var ogp_img_name = ' . "'" . MTEE_OGP_IMG . "'" . '
|
||||
</script>
|
||||
@@ -94,7 +94,7 @@ class="tax-meta-field" />
|
||||
<input class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="' . get_post_meta($tag->term_id, MTEE_OGP_IMG, true) . '" />
|
||||
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
|
||||
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
|
||||
<div id="ogp_media">' . $this->set_ogp_thumb($tag->term_id) . '</div>
|
||||
<div class="ogp_media">' . $this->set_ogp_thumb($tag->term_id) . '</div>
|
||||
<script>
|
||||
var ogp_img_name = ' . "'" . MTEE_OGP_IMG . "'" . '
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
const MTEE_CLASS_DIR = __DIR__ . '/class/';
|
||||
const MTEE_TRAIT_DIR = __DIR__ . '/trait/';
|
||||
const MTEE_TEMPLATE_DIR = __DIR__ . '/template/';
|
||||
const MTEE_NAME_KEYWORDS = 'mtee_meta_keywords';
|
||||
const MTEE_NAME_DESCRIPTION = 'mtee_meta_description';
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ label.mtee-label {
|
||||
margin: .5em 0 0;
|
||||
}
|
||||
|
||||
#ogp_media {
|
||||
.ogp_media {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
|
||||
+39
-30
@@ -20,21 +20,53 @@ jQuery(function ($) {
|
||||
|
||||
function media_uploader() {
|
||||
|
||||
let custom_uploader;
|
||||
let thumb = $('#ogp_media');
|
||||
// let custom_uploader;
|
||||
// let thumb = $('.ogp_media');
|
||||
let select_ogp = $('.select_ogp_img');
|
||||
let clear_ogp = $('.clear_ogp_img');
|
||||
let set_media = [];
|
||||
|
||||
select_ogp.click(function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if (custom_uploader) {
|
||||
custom_uploader.open();
|
||||
let media_index = $('.select_ogp_img').index(this);
|
||||
|
||||
if (set_media[media_index]) {
|
||||
set_media[media_index].open();
|
||||
return;
|
||||
}
|
||||
|
||||
custom_uploader = wp.media({
|
||||
set_media[media_index] = build_media();
|
||||
|
||||
set_media[media_index].on("select", function () {
|
||||
let images = set_media[media_index].state().get("selection");
|
||||
let thumb = $('.ogp_media:eq(' + media_index + ')');
|
||||
/* file の中に選択された画像の各種情報が入っている */
|
||||
images.each(function (file) {
|
||||
/* テキストフォームと表示されたサムネイル画像があればクリア */
|
||||
$('.' + ogp_img_name + ':eq(' + media_index + ')').val('');
|
||||
thumb.empty();
|
||||
/* テキストフォームに画像の ID を表示 */
|
||||
$('.' + ogp_img_name + ':eq(' + media_index + ')').val(file.id);
|
||||
/* プレビュー用に選択されたサムネイル画像を表示 */
|
||||
thumb.append('<img src="' + file.attributes.sizes.thumbnail.url + '" />');
|
||||
});
|
||||
});
|
||||
|
||||
set_media[media_index].open();
|
||||
|
||||
});
|
||||
|
||||
/* クリアボタンを押した時の処理 */
|
||||
clear_ogp.click(function () {
|
||||
let clear_index = $('.clear_ogp_img').index(this);
|
||||
let thumb = $('.ogp_media:eq(' + clear_index + ')');
|
||||
$('.' + ogp_img_name + ':eq(' + clear_index + ')').val('');
|
||||
thumb.empty();
|
||||
});
|
||||
|
||||
function build_media() {
|
||||
return wp.media({
|
||||
title: "画像を選択",
|
||||
/* ライブラリの一覧は画像のみにする */
|
||||
library: {
|
||||
@@ -46,30 +78,7 @@ jQuery(function ($) {
|
||||
/* 選択できる画像は 1 つだけにする */
|
||||
multiple: false
|
||||
});
|
||||
|
||||
custom_uploader.on("select", function () {
|
||||
let images = custom_uploader.state().get("selection");
|
||||
/* file の中に選択された画像の各種情報が入っている */
|
||||
images.each(function (file) {
|
||||
/* テキストフォームと表示されたサムネイル画像があればクリア */
|
||||
$('.' + ogp_img_name).val('');
|
||||
thumb.empty();
|
||||
/* テキストフォームに画像の ID を表示 */
|
||||
$('.' + ogp_img_name).val(file.id);
|
||||
/* プレビュー用に選択されたサムネイル画像を表示 */
|
||||
thumb.append('<img src="' + file.attributes.sizes.thumbnail.url + '" />');
|
||||
});
|
||||
});
|
||||
|
||||
custom_uploader.open();
|
||||
|
||||
});
|
||||
|
||||
/* クリアボタンを押した時の処理 */
|
||||
clear_ogp.click(function () {
|
||||
$('.' + ogp_img_name).val('');
|
||||
thumb.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -46,6 +46,7 @@ if ($mtee->is_enable('canonical_setting')) {
|
||||
|
||||
// enabled my OGP tag
|
||||
if ($mtee->is_enable('ogp_setting')) {
|
||||
include MTEE_TRAIT_DIR . 'mtee_meta_desc_trait.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_ogp_tax_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_ogp_post_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_meta_output_ogp.php';
|
||||
|
||||
+35
-10
@@ -22,12 +22,19 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
<?php wp_nonce_field('check_options'); ?>
|
||||
<div class="mtee_tab_box">
|
||||
<div class="mtee-form-box">
|
||||
<h2>キーワード・ディスクリプション</h2>
|
||||
<h2>メタキーワード・ディスクリプション/OGP</h2>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[enabled]" value="0">
|
||||
<input type="checkbox" name="_mtee[enabled]" <?php checked($enabled, 1); ?>
|
||||
value="1">有効
|
||||
</label>
|
||||
<h3>OGP出力</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[ogp_setting]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[ogp_setting]" <?php checked($ogp_setting, 1); ?>
|
||||
value="1">有効(og:descriptionはmeta descriptionと同じ設定になります)
|
||||
</label>
|
||||
</div>
|
||||
<div class="mtee-form-box mtee_box_border">
|
||||
<h3>meta keywords テンプレート設定
|
||||
@@ -154,15 +161,6 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
value="1">出力しない
|
||||
</label>
|
||||
</div>
|
||||
<div class="mtee-form-box mtee_box_border">
|
||||
<h3>OGPタグ出力</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[ogp_setting]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[ogp_setting]" <?php checked($ogp_setting, 1); ?>
|
||||
value="1">有効
|
||||
</label>
|
||||
</div>
|
||||
<div class="mtee-form-box mtee_box_border">
|
||||
<h3>Canonical URL 出力</h3>
|
||||
<label>
|
||||
@@ -209,6 +207,7 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
$noindex = $opt['top_page']['noindex'] ?? '0';
|
||||
$nofollow = $opt['top_page']['nofollow'] ?? '0';
|
||||
$canonical_url = $opt['top_page']['canonical'] ?? '';
|
||||
$ogp_img = $opt['top_page']['ogp_img'] ?? '';
|
||||
?>
|
||||
<div class="mtee-form-box">
|
||||
<table class="form-table">
|
||||
@@ -270,6 +269,16 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
placeholder="<?php echo get_bloginfo('url'); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP Image</th>
|
||||
<td>
|
||||
<input class="<?php echo MTEE_OGP_IMG; ?>" name="_mtee[top_page][ogp_img]" type="hidden"
|
||||
value="<?php echo $ogp_img; ?>"/>
|
||||
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択"/>
|
||||
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア"/>
|
||||
<div class="ogp_media"><?php echo $this->get_ogp_img('top_page'); ?></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php if (count($register_targets['custom_posts']) > 0): ?>
|
||||
@@ -281,6 +290,7 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
$noindex = $opt['custom_post'][$custom_post]['noindex'] ?? '0';
|
||||
$nofollow = $opt['custom_post'][$custom_post]['nofollow'] ?? '0';
|
||||
$canonical_url = $opt['custom_post'][$custom_post]['canonical'] ?? '0';
|
||||
$ogp_img = $opt['custom_post'][$custom_post]['ogp_img'] ?? '0';
|
||||
?>
|
||||
<?php wp_nonce_field('check_options'); ?>
|
||||
<div class="mtee-form-box">
|
||||
@@ -350,11 +360,26 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
placeholder="<?php echo get_post_type_archive_link($custom_post); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP Image</th>
|
||||
<td>
|
||||
<input class="<?php echo MTEE_OGP_IMG; ?>"
|
||||
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_img]"
|
||||
type="hidden"
|
||||
value="<?php echo $ogp_img; ?>"/>
|
||||
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択"/>
|
||||
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア"/>
|
||||
<div class="ogp_media"><?php echo $this->get_ogp_img('custom_post', $custom_post); ?></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
|
||||
<script>
|
||||
var ogp_img_name = "<?php echo MTEE_OGP_IMG; ?>"
|
||||
</script>
|
||||
</div>
|
||||
</form>
|
||||
<!-- /.wrap -->
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if (!trait_exists('mtee_meta_desc_trait')) {
|
||||
|
||||
trait mtee_meta_desc_trait {
|
||||
|
||||
public function post_output_get_meta_desc($type) {
|
||||
global $post;
|
||||
if ($type == 'top_page') {
|
||||
$meta_description = get_option('_mtee')['top_page']['description'];
|
||||
} elseif ($type == 'custom_post_archive') {
|
||||
$custom_post_name = get_post_type_object(get_post_type())->name;
|
||||
$meta_description = get_option('_mtee')['custom_post'][$custom_post_name]['description'];
|
||||
} elseif ($type == 'custom_tax' || $type == 'category' || $type == 'post_tag') {
|
||||
$queried_object = get_queried_object();
|
||||
$meta_description = get_term_meta($queried_object->term_id, MTEE_NAME_DESCRIPTION, true);
|
||||
} else {
|
||||
$meta_description = get_post_meta($post->ID, MTEE_NAME_DESCRIPTION, true);
|
||||
}
|
||||
return $meta_description;
|
||||
}
|
||||
|
||||
public function create_default_description() {
|
||||
$type = '';
|
||||
$title = '';
|
||||
$suffix_text = MTEE_META_DESC_ARCHIVE_BASE;
|
||||
|
||||
if (is_home() || is_front_page()) { //ページ
|
||||
return MTEE_META_DESC_TOP_BASE;
|
||||
} elseif (is_page() || is_single()) { //ページ
|
||||
$type = 'page';
|
||||
$title = get_the_title();
|
||||
$suffix_text = MTEE_META_DESC_SINGLE_BASE;
|
||||
} elseif (is_category()) { //カテゴリー
|
||||
$type = 'category';
|
||||
$title = single_cat_title('', false);
|
||||
} elseif (is_tag()) { //タグ
|
||||
$type = 'tag';
|
||||
$title = single_tag_title('', false);
|
||||
} elseif (is_tax()) { //タクソノミー
|
||||
$type = 'tax';
|
||||
$title = single_term_title('', false);
|
||||
} elseif (is_post_type_archive()) { //カスタム投稿のアーカイブ
|
||||
$type = 'custom_post';
|
||||
$title = post_type_archive_title('', false);
|
||||
}
|
||||
|
||||
$replacement = $this->cnv_custom_template($type, $title, $suffix_text);
|
||||
|
||||
if (isset($replacement['org'])) {
|
||||
$search = array('<###>', '<%%%>');
|
||||
$description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>';
|
||||
return str_replace($search, $replacement['org'], $description_noun);
|
||||
} else {
|
||||
return $replacement;
|
||||
}
|
||||
}
|
||||
|
||||
public function cnv_custom_template($type, $title, $suffix_text) {
|
||||
if ($type == 'custom_post') {
|
||||
return array('org' => array(post_type_archive_title('', false), $suffix_text));
|
||||
}
|
||||
$template = get_option('_mtee')['description_tmp'];
|
||||
if (isset($template[$type]) && !empty($template[$type])) {
|
||||
$search = array('##title##', '##site_name##', '##site_description##');
|
||||
$replacement = array($title, get_bloginfo('name'), get_bloginfo('description'));
|
||||
return str_replace($search, $replacement, $template[$type]);
|
||||
} else {
|
||||
return array('org' => array($title, $suffix_text));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user