質問編集履歴
2
解決済コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,127 @@
|
|
145
145
|
|
146
146
|
|
147
147
|
よろしくお願いします。
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
###解決済コード
|
152
|
+
|
153
|
+
```ここに言語を入力
|
154
|
+
|
155
|
+
<meta property="og:type" content="blog">
|
156
|
+
|
157
|
+
<!-- OGP -->
|
158
|
+
|
159
|
+
<?php if (is_single() || is_page()) { ?>
|
160
|
+
|
161
|
+
<?php while (have_posts()) : the_post(); ?>
|
162
|
+
|
163
|
+
<meta property="og:title" content="<?php the_title(); ?>" />
|
164
|
+
|
165
|
+
<meta property="og:type" content="article" />
|
166
|
+
|
167
|
+
<?php if (has_post_thumbnail()): ?>
|
168
|
+
|
169
|
+
<?php
|
170
|
+
|
171
|
+
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
172
|
+
|
173
|
+
$src_info = wp_get_attachment_image_src($thumbnail_id, 'large');
|
174
|
+
|
175
|
+
$src = $src_info[0];
|
176
|
+
|
177
|
+
?>
|
178
|
+
|
179
|
+
<meta property="og:image" content="<?php echo $src; ?>" />
|
180
|
+
|
181
|
+
<?php elseif(get_field( 'background', 345 )): ?>
|
182
|
+
|
183
|
+
<?php
|
184
|
+
|
185
|
+
$ogp_img = get_field('background',345);
|
186
|
+
|
187
|
+
//「background」はカスタムフィールドのフィールド名、「345」は設定用に作成した固定ページのID
|
188
|
+
|
189
|
+
$size = "full";
|
190
|
+
|
191
|
+
if( !empty($ogp_img) ): ?>
|
192
|
+
|
193
|
+
<meta property="og:image" content="<?php echo $ogp_img; ?>" />
|
194
|
+
|
195
|
+
<?php endif; ?>
|
196
|
+
|
197
|
+
<?php else: ?>
|
198
|
+
|
199
|
+
<meta property="og:image" content="<?php bloginfo('template_url'); ?>/images/img_ogp.png" />
|
200
|
+
|
201
|
+
<?php endif; ?>
|
202
|
+
|
203
|
+
<meta property="og:url" content="<?php the_permalink(); ?>" />
|
204
|
+
|
205
|
+
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
|
206
|
+
|
207
|
+
<?php endwhile; ?>
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
<?php } elseif (is_home()) { ?>
|
212
|
+
|
213
|
+
<meta property="og:title" content="<?php bloginfo('name'); ?>" />
|
214
|
+
|
215
|
+
<meta property="og:type" content="blog" />
|
216
|
+
|
217
|
+
<?php if(get_field( 'background', 345 )): ?>
|
218
|
+
|
219
|
+
<?php
|
220
|
+
|
221
|
+
$ogp_img = get_field('background',345);
|
222
|
+
|
223
|
+
//「background」はカスタムフィールドのフィールド名、「345」は設定用に作成した固定ページのID
|
224
|
+
|
225
|
+
$size = "full";
|
226
|
+
|
227
|
+
if( !empty($ogp_img) ): ?>
|
228
|
+
|
229
|
+
<meta property="og:image" content="<?php echo $ogp_img; ?>" />
|
230
|
+
|
231
|
+
<?php endif; ?>
|
232
|
+
|
233
|
+
<?php else: ?>
|
234
|
+
|
235
|
+
<meta property="og:image" content="<?php bloginfo('template_url'); ?>/images/img_ogp.png" />
|
236
|
+
|
237
|
+
<?php endif; ?>
|
238
|
+
|
239
|
+
<meta property="og:url" content="<?php bloginfo('url'); ?>" />
|
240
|
+
|
241
|
+
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
|
242
|
+
|
243
|
+
<?php } else { ?>
|
244
|
+
|
245
|
+
<meta property="og:title" content="<?php wp_title('|', true, 'right'); ?><?php bloginfo('name'); ?>" />
|
246
|
+
|
247
|
+
<meta property="og:type" content="article" />
|
248
|
+
|
249
|
+
<meta property="og:image" content="<?php bloginfo('template_url'); ?>/images/img_ogp.png" />
|
250
|
+
|
251
|
+
<meta property="og:url" content="<?php echo get_bloginfo('url').$_SERVER['REQUEST_URI']; ?>" />
|
252
|
+
|
253
|
+
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
|
254
|
+
|
255
|
+
<?php } ?>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
<!-- /OGP -->
|
260
|
+
|
261
|
+
<meta property="og:site_name" content="<?php bloginfo('name'); ?>">
|
262
|
+
|
263
|
+
<meta property="og:locale" content="ja_JP" />
|
264
|
+
|
265
|
+
<meta property="fb:app_id" content="App-ID(15文字の半角数字)">
|
266
|
+
|
267
|
+
<meta name="twitter:card" content="summary_large_image">
|
268
|
+
|
269
|
+
<meta name="twitter:site" content="@twitterID">
|
270
|
+
|
271
|
+
```
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,35 +48,19 @@
|
|
48
48
|
|
49
49
|
<?php
|
50
50
|
|
51
|
-
$
|
51
|
+
$thumbnail_id = get_post_thumbnail_id($post->ID);
|
52
52
|
|
53
|
-
$i
|
53
|
+
$src_info = wp_get_attachment_image_src($thumbnail_id, 'large');
|
54
|
+
|
55
|
+
$src = $src_info[0];
|
54
56
|
|
55
57
|
?>
|
56
58
|
|
59
|
+
<meta property="og:image" content="<?php echo $src; ?>" />
|
60
|
+
|
57
61
|
<?php elseif(post_custom('background')): ?>
|
58
62
|
|
59
|
-
<?php
|
60
|
-
|
61
|
-
$wp_query = new WP_Query();
|
62
|
-
|
63
|
-
$param = array(
|
64
|
-
|
65
|
-
'post_type' => 'page',
|
66
|
-
|
67
|
-
'name' => 'home',
|
68
|
-
|
69
|
-
);
|
70
|
-
|
71
|
-
$wp_query->query( $param );
|
72
|
-
|
73
|
-
if ( $wp_query->have_posts() ): $wp_query->the_post();
|
74
|
-
|
75
|
-
?>
|
76
|
-
|
77
|
-
<meta property="og:image" content="<?php t
|
63
|
+
<meta property="og:image" content="<?php get_field( 'background', 345 ); ?>" />
|
78
|
-
|
79
|
-
<?php endif; ?>
|
80
64
|
|
81
65
|
<?php else: ?>
|
82
66
|
|
@@ -98,7 +82,15 @@
|
|
98
82
|
|
99
83
|
<meta property="og:type" content="blog" />
|
100
84
|
|
85
|
+
<?php if(post_custom('background')): ?>
|
86
|
+
|
87
|
+
<meta property="og:image" content="<?php get_field( 'background', 345 ); ?>" />
|
88
|
+
|
89
|
+
<?php else: ?>
|
90
|
+
|
101
91
|
<meta property="og:image" content="<?php bloginfo('template_url'); ?>/images/img_ogp.png" />
|
92
|
+
|
93
|
+
<?php endif; ?>
|
102
94
|
|
103
95
|
<meta property="og:url" content="<?php bloginfo('url'); ?>" />
|
104
96
|
|