Skip to content
Permalink
Browse files

[add]PWA対応:ホーム画面に追加機能の設定項目を追加

ホーム画面追加のための設定。(manifestファイル、serviceworker.js自体は手動でアップロードを想定)
  • Loading branch information...
ultimate-ez committed Aug 11, 2017
1 parent 6e2d790 commit a6bfcc547a52f981defb8c35fb7ac39650f304bf
Showing with 43 additions and 0 deletions.
  1. +23 −0 functions.php
  2. +20 −0 se-customizer.php
@@ -260,6 +260,29 @@ function sentry_page_ad(){
}
add_action( 'wp_head', 'sentry_page_ad' );
if ( ! function_exists( 'sentry_pwa_manifest') ) {
function sentry_pwa_manifest(){
if ( get_theme_mod('pwa_manifest')){
?>
<link rel="manifest" href="/manifest.json">
<script>
window.addEventListener('load', function() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("/serviceWorker.js" )
.then(function(registration) {
console.log("serviceWorker registed.");
}).catch(function(error) {
console.warn("serviceWorker error.", error);
});
}
});
</script>
<?php
}
}
}
add_action( 'wp_head', 'sentry_pwa_manifest' );
// SNS Count 桁数の調整
if ( ! function_exists( 'sentry_sns_count_carry' ) ) {
function sentry_sns_count_carry($count) {
@@ -131,6 +131,7 @@ function mytheme_customize_register( $wp_customize ){
'priority' => 3,
));
// AMPの設定
$wp_customize->add_section( 'sentry_amp_section', array(
'title' => 'AMPページ設定',
'priority' => 60,
@@ -181,6 +182,25 @@ function mytheme_customize_register( $wp_customize ){
'priority' => 22,
));
// PWAの設定
$wp_customize->add_section( 'sentry_pwa_section', array(
'title' => 'PWA設定',
'priority' => 70,
));
$wp_customize->add_setting( 'pwa_manifest', array(
'default' => false,
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_checkbox',
));
$wp_customize->add_control( 'pwa_manifest_c', array(
'section' => 'sentry_pwa_section',
'settings' => 'pwa_manifest',
'label' => 'PWA用のHTMLを出力する',
'description' =>'PWA用のHTMLを出力します。<br>manifest.jsonはサイトのルートに設置してください。<br>PWS設定方法の詳細は<a href="https://ultimate-ez.com/2017/08/12/4846/?utm_source=sentry&utm_medium=customizer&utm_campaign='.get_home_url().'" target="_blank">こちら</a>。',
'type' => 'checkbox',
'priority' => 10,
));
}
add_action( 'customize_register', 'mytheme_customize_register' );
?>

0 comments on commit a6bfcc5

Please sign in to comment.
You can’t perform that action at this time.