WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ設定の追加

・language_attributesフックでhtmlタグにprefixを追加
This commit is contained in:
2021-05-28 21:06:37 +09:00
parent 21ccef70f1
commit 151026ef87
2 changed files with 82 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_ogp_setting')) {
class mtee_ogp_setting {
public function __construct() {
//Posts
//add_action('admin_menu', array($this, 'add_meta_fields'));
}
//-------------------------------------------------------------------------------------------
// 投稿、ページのカスタムフィールド設定
//-------------------------------------------------------------------------------------------
public function add_meta_fields() {
//add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
$default_built_ins = array(
'posts' => array('page', 'post',),
);
foreach ($default_built_ins['posts'] as $built_in) {
add_meta_box(
'canonical_setting',
'Canonical設定',
array($this, 'insert_meta_fields'),
$built_in,
'normal'
);
}
if (isset($this->options['custom_posts'])) {
foreach ($this->options['custom_posts'] as $custom_post => $post_chk) {
if ($post_chk == 1) {
add_meta_box(
'canonical_setting',
'Canonical設定',
array($this, 'insert_meta_fields'),
$custom_post, 'normal'
);
}
}
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_ogp')) {
class mtee_meta_output_ogp {
public function __construct() {
//GOPのプレフィックスを出力する
add_filter('language_attributes', array($this, 'add_html_ogp_prefix'));
}
/**
* GOPのプレフィックスを設定する
* @param $output
* @return string
*/
public function add_html_ogp_prefix($output): string {
$output .= $this->create_ogp_prefix();
return $output;
}
private function create_ogp_prefix(): string {
return ' prefix="og: https://ogp.me/ns#"';
}
}
}