WordPressテーマ変更!SimplicityからCocoonへ
スポンサーリンク

functions.phpエラー頻発!!構文あってるよねっ!?ブログが見れなくなるエラーが何かわからない!!その時初心者がとった手段、ブログに書いてツイッターで解答してもらった★最中のページ♪

会話の延長から、わからない事を教えてもらう事になった時の当時の現在進行形の質問になってます。
普通に聞けば良いんでしょうけど、、何をどう伝えたら良いのかわかんなくって。。ブログにしたら、何行目とかソースとか貼り付けた場所とか説明しやすいかと思ってやったことです。

その時の経緯は目次から、エラーの原因を書いたページのurlを貼ってます。

ブログで自分のやった事、ソースをどこに貼り付けたかを書いただけのページから始まったのでいきなり会話文から始まってます。

 

ど素人プリが、凄くっスミマセン。。

何か!?
どこかを勘違いしてるはずなんですよねっ。。

そこがサッパリわかんないですっ??

参考にさせてもらったんですけどやり方がまずくってスミマセン。。

@loveguavaさん:ブログのアドセンス収益を1.3倍アップさせる方法。広告サイズとスマホを意識した配置がポイント!

できなくってすみません。。(*ノノ)

スポンサーリンク

エラー画面のコピペ

解析エラー:構文エラー、予期しない$エンド ライン300

エラーコード原文

Parse error: syntax error, unexpected $end in /home/users/0/×××.×××-×××-×××/web/bibabosi-rizumu.com/wp-content/themes/stinger5Ladyver20141023/functions.php on line 300

この構文の×××.×××-・・・これは、表示されたくないサーバーアカウントなんですよっ♪
なので、.htaccsessで、表示させないよう設定を・・って思ったら、反映されません。。それは、ロリポップのphpの設定で初期設定が反映させない設定なんです。

その事と、あわせてphpエラーの直し方など含めて書いたページを紹介します♪
リコメン:phpエラーで個人情報が丸見えに!!ロリポップ使用者必見★回避するなら設定しよう♪対処方法を全公開!

私が、functions.php 記載したものすべて。

161~アドセンスについて記載事項

//アドセンス
function add_ads_before_1st_h2($the_content) {
  if (is_single()) {
    if (wp_is_mobile()) {
      $ads = <<< EOF
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル中 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
      EOF;
    } else {
      $ads = <<< EOF
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル大 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
      EOF;
    }
    $h2 = '/<h2.*?>/i';//H2見出しのパターン
    if ( preg_match( $h2, $the_content, $h2s )) {//H2見出しが本文中にあるかどうか
      $the_content  = preg_replace($h2, $ads.$h2s[0], $the_content, 1);//最初のH2を置換
    }
  }
  return $the_content;
}
add_filter('the_content','add_ads_before_1st_h2');

198~スマホ・PC、アドセンス広告を別にするコードを記載

//スマホ PC アドセンス広告 別にするコード
<?php if ( function_exists('wp_is_mobile') && wp_is_mobile() ) :?>
★<!-- レクタングル中 -->★
<?php else: ?>
★アドセンス、レクタングル大のコードを記載★
<?php endif; ?>

上記をfunctions.phpにコピペしてみました♪→コレは、ここに書く内容ではない、single.phpの任意の場所に書く内容です♪

昨日のエラーは、コレのみ記載しました♪
エラーでブログ&投稿画面が真っ白に!元に戻す方法とは!?【functions.php更新→ Parse errorその時の行動&記録♪】

functions.php記載している全てです❣

<?php
function register_jq_script() {
    if (!is_admin()) {
        $script_dir = get_template_directory_uri();
        wp_deregister_script( 'jquery' );
        wp_enqueue_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js',array(), false, false);
    }
}
add_action('wp_enqueue_scripts','register_jq_script');

//WordPress の投稿スラッグを自動的に生成する
function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) {
    if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) {
        $slug = utf8_uri_encode( $post_type ) . '-' . $post_ID;
    }
    return $slug;
}
add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4  );

//カスタム背景
$custom_bgcolor_defaults = array(
        'default-color' => '#f2f2f2',
);
add_theme_support( 'custom-background', $custom_bgcolor_defaults );

//カスタムヘッダー
$custom_header = array(
 'random-default' => false,
 'width' => 980,
 'height' => 250,
 'flex-height' => true,
 'flex-width' => false,
 'default-text-color' => '',
 'header-text' => false,
 'uploads' => true,
 'default-image' => get_template_directory_uri() . '/images/stinger5.png',
);
add_theme_support( 'custom-header', $custom_header );

// 抜粋の長さを変更する
function custom_excerpt_length( $length ) {
     return 40; 
}   
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

// 文末文字を変更する
function custom_excerpt_more($more) {
    return ' ... ';
}
add_filter('excerpt_more', 'custom_excerpt_more');

//スマホ表示分岐
function is_mobile(){
    $useragents = array(
        'iPhone', // iPhone
        'iPod', // iPod touch
        'Android.*Mobile', // 1.5+ Android *** Only mobile
        'Windows.*Phone', // *** Windows Phone
        'dream', // Pre 1.5 Android
        'CUPCAKE', // 1.5+ Android
        'blackberry9500', // Storm
        'blackberry9530', // Storm
        'blackberry9520', // Storm v2
        'blackberry9550', // Storm v2
        'blackberry9800', // Torch
        'webOS', // Palm Pre Experimental
        'incognito', // Other iPhone browser
        'webmate' // Other iPhone browser

    );
    $pattern = '/'.implode('|', $useragents).'/i';
    return preg_match($pattern, $_SERVER['HTTP_USER_AGENT']);
}
//アイキャッチサムネイル
add_theme_support('post-thumbnails');
add_image_size('thumb100',100,100,true);
add_image_size('thumb150',150,150,true);


//カスタムメニュー
register_nav_menus(array('navbar' => 'ナビゲーションバー'));

//RSS
add_theme_support('automatic-feed-links');

// 管理画面にオリジナルのスタイルを適用
add_editor_style("style.css");  // メインのCSS
add_editor_style('editor-style.css');   // これは入れておこう
if ( ! isset( $content_width ) ) $content_width = 580;
function custom_editor_settings( $initArray ){
    $initArray['body_id'] = 'primary';  // id の場合はこれ
    $initArray['body_class'] = 'post';  // class の場合はこれ
    return $initArray;
}
add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );

//投稿用ファイルを読み込む
get_template_part('functions/create-thread');

//ページャー機能
function pagination($pages = '', $range = 4)
{
     $showitems = ($range * 2)+1;

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     } 

     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link

(1)."'>&laquo; First</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;

Previous</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems

))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link

($i)."' class=\"inactive\">".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged +

1)."\">Next &rsaquo;</a>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a

href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}

//ヘッダーを綺麗に
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action( 'wp_head', 'wp_generator' );

//moreリンク
function custom_content_more_link( $output ) {
    $output = preg_replace('/#more-[\d]+/i', '', $output );
    return $output;
}
add_filter( 'the_content_more_link', 'custom_content_more_link' );

//アドセンス
function add_ads_before_1st_h2($the_content) {
  if (is_single()) {
    if (wp_is_mobile()) {
      $ads = <<< EOF
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル中 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
      EOF;
    } else {
      $ads = <<< EOF
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル大 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
      EOF;
    }
    $h2 = '/<h2.*?>/i';//H2見出しのパターン
    if ( preg_match( $h2, $the_content, $h2s )) {//H2見出しが本文中にあるかどうか
      $the_content  = preg_replace($h2, $ads.$h2s[0], $the_content, 1);//最初のH2を置換
    }
  }
  return $the_content;
}
add_filter('the_content','add_ads_before_1st_h2');

//スマホ PC アドセンス広告 別にするコード
<?php if ( function_exists('wp_is_mobile') && wp_is_mobile() ) :?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル中 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php else: ?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- レクタングル大 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-×コード×"
     data-ad-slot="×数字×"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php endif; ?>

//セルフピンバック禁止
function no_self_ping( &$links ) {
    $home = home_url();
    foreach ( $links as $l => $link )
        if ( 0 === strpos( $link, $home ) )
            unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );

//iframeのレスポンシブ対応
function wrap_iframe_in_div($the_content) {
  if ( is_singular() ) {
    $the_content = preg_replace('/< *?iframe/i', '<div class="youtube-container"><iframe', $the_content);
    $the_content = preg_replace('/<\/ *?iframe *?>/i', '</iframe></div>', $the_content);
  }
  return $the_content;
}
add_filter('the_content','wrap_iframe_in_div');

//ウイジェット追加
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) )
register_sidebars(1,
    array(
    'name'=>'サイドバーウイジェット',
    'before_widget' => '<ul><li>',
    'after_widget' => '</li></ul>',
    'before_title' => '<h4 class="menu_underh2">',
    'after_title' => '</h4>',
    ));
register_sidebars(1,
    array(
    'name'=>'スクロール広告用',
    'description' => '「テキスト」をここにドロップして内容を入力して下さい。アドセンスは禁止です。※PC以外では非表示部分',
    'before_widget' => '<ul><li>',
    'after_widget' => '</li></ul>',
    'before_title' => '<h4 class="menu_underh2" style="text-align:left;">',
    'after_title' => '</h4>',
    ));
register_sidebars(1,
    array(
    'name'=>'Googleアドセンス用336px',
    'description' => '「テキスト」をここにドロップしてコードを入力して下さい。タイトルは反映されません。',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4 style="display:none">',
    'after_title' => '</h4>',
    ));

register_sidebars(1,
    array(
    'name'=>'Googleアドセンスのスマホ用300px',
    'description' => '「テキスト」をここにドロップしてコードを入力して下さい。タイトルは反映されません。',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4 style="display:none">',
    'after_title' => '</h4>',
    ));


//更新日の追加
function get_mtime($format) {
    $mtime = get_the_modified_time('Ymd');
    $ptime = get_the_time('Ymd');
    if ($ptime > $mtime) {
        return get_the_time($format);
    } elseif ($ptime === $mtime) {
        return null;
    } else {
        return get_the_modified_time($format);
    }
}

単一記事の投稿 (single.php)を見てもらおう♪

記事下がどれだか・・?お手数おかけしてます。。

 

よろしくお願いします。ペコリッ

<?php get_header(); ?>

<div id="content" class="clearfix">
  <div id="contentInner">
    <main>
      <article>
        <div class="post"> 
          <!--ぱんくず -->
          <div id="breadcrumb">
            <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <a href="<?php echo home_url(); ?>" itemprop="url"> <span itemprop="title">ホーム</span> </a> &gt; </div>
            <?php $postcat = get_the_category(); ?>
            <?php $catid = $postcat[0]->cat_ID; ?>
            <?php $allcats = array($catid); ?>
            <?php 
while(!$catid==0) {
    $mycat = get_category($catid);
    $catid = $mycat->parent;
    array_push($allcats, $catid);
}
array_pop($allcats);
$allcats = array_reverse($allcats);
?>
            <?php foreach($allcats as $catid): ?>
            <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <a href="<?php echo get_category_link($catid); ?>" itemprop="url"> <span itemprop="title"><?php echo get_cat_name($catid); ?></span> </a> &gt; </div>
            <?php endforeach; ?>
          </div>
          <!--/ ぱんくず -->
<!--ツイッターフォローボタン -->
 <a href="https://twitter.com/kautakku" class="twitter-follow-button" data-show-count="false" data-lang="ja" data-size="large" data-dnt="true">@kautakkuさんをフォロー</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
  <!--/ ツイッターフォローボタン -->       
          <section> 
            <!--ループ開始 -->
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <h1 class="entry-title">
              <?php the_title(); //タイトル ?>
            </h1>
            <div class="blogbox">
              <p><span class="kdate"><i class="fa fa-calendar"></i>&nbsp;
                <time class="entry-date" datetime="<?php the_time('c') ;?>">
                  <?php the_time('Y/m/d') ;?>
                </time>
                &nbsp;
                <?php if ($mtime = get_mtime('Y/m/d')) echo ' <i class="fa fa-repeat"></i>&nbsp; ' , $mtime; ?>
                </span> </p>
            </div>
            <?php the_content(); //本文 ?>
          </section>
          <!--/section-->
          <?php wp_link_pages(); ?>
          <p class="tagst"><i class="fa fa-tags"></i>&nbsp;-
            <?php the_category(', ') ?>
            <?php the_tags('', ', '); ?>
          </p>
          <div style="padding:20px 0px;">
            <?php get_template_part('ad'); //アドセンス読み込み ?>
            <?php if(is_mobile()) { //スマホの場合 ?>
            <?php } else { //PCの場合 ?>
            <div class="smanone" style="padding-top:10px;">
              <?php get_template_part('ad'); //アドセンス読み込み ?>
            </div>
            <?php } ?>
          </div>
<!--ツイッター埋め込みタイムライン-->
<a class="twitter-timeline" href="https://twitter.com/kautakku" data-widget-id="590205998154928128">@kautakkuさんのツイート</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
          <?php get_template_part('sns'); //ソーシャルボタン読み込み ?>
          <?php endwhile; else: ?>
          <p>記事がありません</p>
          <?php endif; ?>
          <!--ループ終了-->
          
          <?php if( comments_open() || get_comments_number() ){
          comments_template(); } ?>
          <!--関連記事-->
          <h4 class="point"><i class="fa fa-th-list"></i>&nbsp;  関連記事</h4>
          <?php get_template_part('kanren');?>
          
          <!--ページナビ-->
          <div class="p-navi clearfix">
            <dl>
              <?php
        $prev_post = get_previous_post();
        if (!empty( $prev_post )): ?>
              <dt>PREV </dt>
              <dd><a href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo $prev_post->post_title; ?></a></dd>
              <?php endif; ?>
              <?php
        $next_post = get_next_post();
        if (!empty( $next_post )): ?>
              <dt>NEXT </dt>
              <dd><a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo $next_post->post_title; ?></a></dd>
              <?php endif; ?>
            </dl>
          </div>
        </div>
        <!--/post--> 
      </article>
    </main>
  </div>
  <!-- /#contentInner -->
  <?php get_sidebar(); ?>
</div>
<!--/#content -->
<?php get_footer(); ?>

エラーの原因は、何だったのか?別ページで結果を見てみよう♪

原因は、

エラーの原因は、スペースにあった。これは、1人じゃ気付けなかった

161行目からの、正しいソースはEOF前のスペースを抜いた構文。

スペースがあったので、エラーが発生しました。エラーの原因は、なんだったのか?で、記載しています♪

198~スマホ・PC、アドセンス広告を別にするコードを記載

この部分は、丸ごと 単一記事の投稿 (single.php) の任意の場所へ追記すれば良いんです。

でも、アドセンスの数は、またゴチョゴチョして調整必要でした。

以下、省略とします。気に留めていただいてありがとうございます。

エローラさん、あめたまさん、かみじょーさん、杉成就さん、おくたにさん、sachikoさん♪困ってる時メッセージくれたり、エラー直してくれるお手伝いして頂きまして、ありがとうございました!前編で、その時の経緯をざっくりですが、感謝を込めて書きとめてます♪

ページが白く上のほうに文字がゴチョゴチョ書いたページになってしまうエラーの直し方ページへジャンプ

真っ白になったんじゃないんですけど、その時ブログとかに入ると、白い画面の上部に文字がゴチョゴチョっと書いてるエラーが出てしまって。。

その直し方をツラツラ書いたページを貼っておきますねっ♪

この全貌は、3ページにわたる事になりました。4ページ目まで見てもらえたら、うれしいです♪

エラーでブログ&投稿画面が真っ白に!元に戻す方法とは!?【functions.php更新→ Parse errorその時の行動&記録♪】

ここがこのページの始まりであって、以降このページがはじまった経緯のページその後、おせわになった人を紹介しちゃよぉ~♪ってページへ続く事になりました♪

関係していただいた皆さんに感謝してます♪

そして、ここをのぞいてくださったあなたに♪

どうもありがとうございましたっ。ペコリッ

この記事が気に入ったら
いいね!しよう
最新情報をお届けします。
WordPress
フォローする
スポンサーリンク
スポンサーリンク
ビバ★りずむ

Comments

個人情報の取り扱いについてはリンク先をご確認ください。

ご了承・ご理解いただいた上でコメントお待ちしております?

トップへ戻る
タイトルとURLをコピーしました