Skip to content

Commit

Permalink
[add]PWA対応:ホーム画面に追加機能の設定項目を追加
Browse files Browse the repository at this point in the history
ホーム画面追加のための設定。(manifestファイル、serviceworker.js自体は手動でアップロードを想定)
  • Loading branch information
ultimate-ez committed Aug 11, 2017
1 parent 6e2d790 commit a6bfcc5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions se-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.