diff --git a/class/mtee_meta_output_ogp.php b/class/mtee_meta_output_ogp.php index 03054d2..2336765 100644 --- a/class/mtee_meta_output_ogp.php +++ b/class/mtee_meta_output_ogp.php @@ -10,12 +10,12 @@ if (!class_exists('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 $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'); @@ -53,7 +53,9 @@ if (!class_exists('mtee_meta_output_ogp')) { $tags .= '' . PHP_EOL; $tags .= '' . PHP_EOL; $tags .= '' . PHP_EOL; -// $tags .= '' . PHP_EOL; + if (!empty($this->ogp_img)) { + $tags .= '' . PHP_EOL; + } $tags .= '' . PHP_EOL; // $tags .= '' . PHP_EOL; // $tags .= '' . PHP_EOL; @@ -80,6 +82,24 @@ if (!class_exists('mtee_meta_output_ogp')) { } public function create_ogp_title() { + global $post; + if (is_home() || is_front_page()) { + $this->ogp_title = get_option('_mtee')['top_page']['ogp_title']; + } elseif (is_post_type_archive()) { + $custom_post_name = get_post_type_object(get_post_type())->name; + $this->ogp_title = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_title']; + } elseif (is_category() || is_tag() || is_tax()) { + $queried_object = get_queried_object(); + $this->ogp_title = get_term_meta($queried_object->term_id, MTEE_OGP_TITLE, true); + } elseif (is_page() || is_single()) { + $this->ogp_title = get_post_meta($post->ID, MTEE_OGP_TITLE, true); + } + if (empty($this->ogp_title)) { + $this->create_default_title(); + } + } + + public function create_default_title() { if (is_category()) { $this->ogp_title = single_cat_title('', false); } elseif (is_tag()) { @@ -96,11 +116,29 @@ if (!class_exists('mtee_meta_output_ogp')) { } public function create_ogp_description() { - $this->ogp_description = $this->site_name . MTEE_META_DESC_PARTICLE; - $this->ogp_description .= $this->set_ogp_description(); + $this->create_input_description(); + if (empty($this->ogp_description)) { + $this->set_default_description(); + } } - public function set_ogp_description() { + public function create_input_description() { + global $post; + if (is_home() || is_front_page()) { + $this->ogp_description = get_option('_mtee')['top_page']['ogp_description']; + } elseif (is_post_type_archive()) { + $custom_post_name = get_post_type_object(get_post_type())->name; + $this->ogp_description = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_description']; + } elseif (is_category() || is_tag() || is_tax()) { + $queried_object = get_queried_object(); + $this->ogp_description = get_term_meta($queried_object->term_id, MTEE_OGP_DESC, true); + } elseif (is_page() || is_single()) { + $this->ogp_description = get_post_meta($post->ID, MTEE_OGP_DESC, true); + } + } + + public function set_default_description() { + $this->ogp_description = $this->site_name . MTEE_META_DESC_PARTICLE; $type = ''; $ogp_desc = ''; @@ -126,13 +164,12 @@ if (!class_exists('mtee_meta_output_ogp')) { } if (!empty($type)) { - $ogp_desc = $this->post_output_get_meta_desc($type); + $this->ogp_description .= $this->post_output_get_meta_desc($type); } if (empty($ogp_desc)) { - $ogp_desc = $this->create_default_description(); + $this->ogp_description .= $this->create_default_description(); } - return $ogp_desc; } @@ -160,81 +197,59 @@ if (!class_exists('mtee_meta_output_ogp')) { public function create_ogp_image() { global $post; - $id = ''; - $type = ''; if (is_post_type_archive()) { - $type = 'custom_post_archive'; + $this->set_custom_post_archive_ogp_img(); } elseif (is_category()) { - $id = get_query_var('cat'); - $type = 'cat'; + $this->set_category_ogp_img(get_query_var('cat')); } elseif (is_tag()) { - $id = get_query_var('tag_id'); - $type = 'tag'; + $this->set_tag_ogp_img(get_query_var('tag_id')); } elseif (is_tax()) { - $id = get_queried_object()->term_id; - $type = 'tax'; + $this->set_tax_ogp_img(get_queried_object()->term_id); } elseif (is_home() || is_front_page()) { - $type = 'top_page'; + $this->set_top_page_ogp_img(); } 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); + $this->set_post_ogp_img($post->ID); } } public function set_top_page_ogp_img() { - $img = get_option('_mtee')['top_page']['ogp_img']; - if (empty($img)) { - $img = ''; - } - return $img; + $id = get_option('_mtee')['top_page']['ogp_img']; + $this->get_thumbnail($id); } 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; + $id = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_img']; + $this->get_thumbnail($id); } public function set_post_ogp_img($id) { - $img = get_post_meta($id, MTEE_OGP_IMG, true); - + $id = get_post_meta($id, MTEE_OGP_IMG, true); + $this->get_thumbnail($id); } public function set_category_ogp_img($id) { - $img = get_term_meta($id, MTEE_OGP_IMG, true); - + $id = get_term_meta($id, MTEE_OGP_IMG, true); + $this->get_thumbnail($id); } public function set_tag_ogp_img($id) { - $img = get_term_meta($id, MTEE_OGP_IMG, true); - + $id = get_term_meta($id, MTEE_OGP_IMG, true); + $this->get_thumbnail($id); } public function set_tax_ogp_img($id) { - $img = get_term_meta($id, MTEE_OGP_IMG, true); - + $id = get_term_meta($id, MTEE_OGP_IMG, true); + $this->get_thumbnail($id); } + public function get_thumbnail($id) { + if (!empty($id)) { + $this->ogp_img = wp_get_attachment_url($id); + } elseif (has_post_thumbnail($id)) { + $this->ogp_img = wp_get_attachment_url(get_post_thumbnail_id($id)); + } + } } } \ No newline at end of file diff --git a/meta-tag-etc-extend.php b/meta-tag-etc-extend.php index e544f29..a6ea290 100644 --- a/meta-tag-etc-extend.php +++ b/meta-tag-etc-extend.php @@ -8,7 +8,13 @@ Version: 1.0 /* Todo:OGPタグ -タグの出力 +画像出力 + +facebook + + +Twitter + */ include_once 'config.php'; diff --git a/template/index.php b/template/index.php index 2a46594..3345873 100644 --- a/template/index.php +++ b/template/index.php @@ -207,6 +207,8 @@ $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_title = $opt['top_page']['ogp_title'] ?? ''; + $ogp_description = $opt['top_page']['ogp_description'] ?? ''; $ogp_img = $opt['top_page']['ogp_img'] ?? ''; ?>
| meta keywords | +
+ キーワードはカンマ(,)区切りで入力してください + |
+
|---|---|
| meta description | ++ | +
| meta keywords | +
+ キーワードはカンマ(,)区切りで入力してください + |
+
|---|---|
| meta description | ++ | +