[WordPress] twitter/Facebook/Google+/Pocket/LINE/はてなブックマーク独自ボタン
2017/09/24 Pocketのバグを改善しました。
header.php OGP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!-- OGP --> <meta property="og:locale" content="ja_JP"> <?php if (is_single()): ?> <meta property="og:type" content="article"> <?php else: ?> <meta property="og:type" content="website"> <?php endif; ?> <meta property="og:url" content="<?php echo ('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>"> <?php if (is_single() && has_post_thumbnail()): ?> <meta property="og:image" content="<?php the_post_thumbnail_url(); ?>"> <?php else: ?> <meta property="og:image" content="<?php echo esc_url(get_template_directory_uri()); ?>/images/img_profile.png"> <?php endif; ?> <?php if (is_single()): ?> <meta property="og:title" content="<?php the_title(); ?>"> <meta property="og:description" content="<?php echo mb_substr(str_replace(array("\r\n" , "\n" , "\r"), '', strip_tags($post->post_content)), 0, 100); ?>"> <?php else: ?> <meta property="og:title" content="<?php bloginfo('name'); ?>"> <meta property="og:description" content="<?php bloginfo('description'); ?>"> <?php endif; ?> <!-- twitter --> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="@keitahirai"> |
single.php
ページURLとページタイトルのgetタグをエンコードし、変数に格納してecho呼び出し。
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $url_e = urlencode(get_permalink()); $title_e = urlencode(get_the_title()); ?> <ul> <li><a href="https://twitter.com/intent/tweet?url=<?php echo $url_e ?>&text=<?php echo $title_e ?>&via=keitahirai" target="_blank">twitter</a></li> <li><a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $url_e ?>&t=<?php echo $title_e ?>" target="_blank">Facebook</a></li> <li><a href="https://plus.google.com/share?url=<?php echo $url_e ?>" target="_blank">Google+</a></li> <li><a href="https://getpocket.com/edit?url=<?php echo $url_e ?>" target="_blank">Pocket</a></li> <li><a href="http://line.me/R/msg/text/?<?php echo $title_e ?> <?php echo $url_e ?>" target="_blank">LINE</a></li> <li><a href="http://b.hatena.ne.jp/add?url=<?php echo $url_e ?>" target="_blank">はてなブックマーク</a></li> </ul> |
developers.google.com/+/web/share/?hl=ja
上記LINEコードは、昨年10月まで公式サイトで確認できたが現在は削除。
使用不可になるまでこれで対応。
はてなブックマークも公式未掲載のコードだが、使えるのでオッケー。
コメントを投稿する