WP PLUGIN MTEE(Meta Tag etc Extend) OGP設定
・OGP imageの設定 ・トップページとカスタム投稿アーカイブのOGP title、description追加 ・タイトルとディスクリプションの出力
This commit is contained in:
@@ -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 .= '<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;
|
||||
if (!empty($this->ogp_img)) {
|
||||
$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;
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,13 @@ Version: 1.0
|
||||
|
||||
/*
|
||||
Todo:OGPタグ
|
||||
タグの出力
|
||||
画像出力
|
||||
|
||||
facebook
|
||||
<meta property="fb:app_id" content="[FacebookアプリのID]" />
|
||||
|
||||
Twitter
|
||||
|
||||
*/
|
||||
|
||||
include_once 'config.php';
|
||||
|
||||
+47
-3
@@ -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'] ?? '';
|
||||
?>
|
||||
<div class="mtee-form-box">
|
||||
@@ -218,7 +220,7 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
<?php endif; ?>
|
||||
</th>
|
||||
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][keywords]"
|
||||
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
|
||||
value="<?php echo $keywords; ?>">
|
||||
<br>キーワードはカンマ(,)区切りで入力してください
|
||||
</td>
|
||||
</tr>
|
||||
@@ -269,6 +271,26 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
placeholder="<?php echo get_bloginfo('url'); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP title
|
||||
<?php if (!$this->is_enable('enabled')): ?>
|
||||
<span class="disabled_status">※現在無効です</span>
|
||||
<?php endif; ?>
|
||||
</th>
|
||||
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][ogp_title]"
|
||||
value="<?php echo $ogp_title; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP description
|
||||
<?php if (!$this->is_enable('enabled')): ?>
|
||||
<span class="disabled_status">※現在無効です</span>
|
||||
<?php endif; ?>
|
||||
</th>
|
||||
<td><input class="top_page_description" type="text" name="_mtee[top_page][ogp_description]"
|
||||
value="<?php echo $ogp_description; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP Image</th>
|
||||
<td>
|
||||
@@ -289,8 +311,10 @@ $rss_disabled = $this->get_key_setting('rss_disabled');
|
||||
$description = $opt['custom_post'][$custom_post]['description'] ?? '';
|
||||
$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';
|
||||
$canonical_url = $opt['custom_post'][$custom_post]['canonical'] ?? '';
|
||||
$ogp_title = $opt['custom_post'][$custom_post]['ogp_title'] ?? '';
|
||||
$ogp_description = $opt['custom_post'][$custom_post]['ogp_description'] ?? '';
|
||||
$ogp_img = $opt['custom_post'][$custom_post]['ogp_img'] ?? '';
|
||||
?>
|
||||
<?php wp_nonce_field('check_options'); ?>
|
||||
<div class="mtee-form-box">
|
||||
@@ -360,6 +384,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 keywords
|
||||
<?php if (!$this->is_enable('enabled')): ?>
|
||||
<span class="disabled_status">※現在無効です</span>
|
||||
<?php endif; ?></th>
|
||||
<td><input class="top_page_keywords" type="text"
|
||||
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_title]"
|
||||
value="<?php echo $ogp_title; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP description
|
||||
<?php if (!$this->is_enable('enabled')): ?>
|
||||
<span class="disabled_status">※現在無効です</span>
|
||||
<?php endif; ?></th>
|
||||
<td><input class="top_page_description" type="text"
|
||||
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_description]"
|
||||
value="<?php echo $ogp_description; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>OGP Image</th>
|
||||
<td>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<h2 class="mtee_page_title mtee_box_border">トップページ</h2>
|
||||
<?php
|
||||
$keywords = $opt['top_page']['keywords'] ?? '';
|
||||
$description = $opt['top_page']['description'] ?? '';
|
||||
?>
|
||||
<div class="mtee-form-box">
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th>meta keywords</th>
|
||||
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][keywords]"
|
||||
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
|
||||
<br>キーワードはカンマ(,)区切りで入力してください
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>meta description</th>
|
||||
<td><input class="top_page_description" type="text" name="_mtee[top_page][description]"
|
||||
value="<?php echo $description; ?>"
|
||||
placeholder="<?php echo get_bloginfo('name'); ?>の<?php echo MTEE_META_DESC_TOP_BASE; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php if (count($register_targets['custom_posts']) > 0): ?>
|
||||
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
|
||||
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
|
||||
<?php
|
||||
$keywords = $opt['custom_post'][$custom_post]['keywords'] ?? '';
|
||||
$description = $opt['custom_post'][$custom_post]['description'] ?? '';
|
||||
?>
|
||||
<?php wp_nonce_field('check_options'); ?>
|
||||
<div class="mtee-form-box">
|
||||
<h3 class="mtee_page_archive_title">
|
||||
<?php echo get_post_type_object($custom_post)->label; ?>
|
||||
(<?php echo $custom_post; ?>)
|
||||
</h3>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th>meta keywords</th>
|
||||
<td><input class="top_page_keywords" type="text"
|
||||
name="_mtee[custom_post][<?php echo $custom_post; ?>][keywords]"
|
||||
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
|
||||
<br>キーワードはカンマ(,)区切りで入力してください
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>meta description</th>
|
||||
<td><input class="top_page_description" type="text"
|
||||
name="_mtee[custom_post][<?php echo $custom_post; ?>][description]"
|
||||
value="<?php echo $description; ?>"
|
||||
placeholder="<?php echo get_bloginfo('name'); ?>の[カスタム投稿ラベル]<?php echo MTEE_META_DESC_ARCHIVE_BASE; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user