カテゴリー: TECH NOTES

  • gtag ampページ設置

    サイトをAMPに対応させたところ、どうしてもGoogle Analyticsのトラッキングコードがサマリーに反映されない。

    調べてみると、AMP対応のサイトでGA4はまだ使えないとのこと。

    従来のGoogle Analytics (ユニバーサルアナリティクス) 、UAからはじまるトラッキングIDを使用すべきとのこと。

    Googleが推奨しているAMPでGoogleが非推奨している旧トラッキングコードしか使えないというまさかのオチでした。

    ハマった方も結構いるのではないでしょうか。

    ちなみにGA4の改悪の一つはデータ保持期間ではないだろうか。現在のところ2ヶ月と14ヶ月しか選択できないのにたいし、従来のGoogle Analytics (ユニバーサルアナリティクス)は期限無しで保存可能。

    そのあたりもGoogleが非推奨にしている理由のひとつなのかと。

  • wordpress 管理画面内、投稿一覧ページで投稿者で並び替え

    以下をfuncion.phpに追加

    function ag_custom_post_type_order($wp_query) {
    if( is_admin() ) {
    $post_type = $wp_query->query['post_type'];
    if($post_type == '投稿タイプ') { //page post ...
    $wp_query->set('orderby','author'); //ソートの基準を設定:日付の場合は date
    $wp_query->set('order','DESC'); //ASC Or DESC で昇順・降順を設定
    }
    }
    }
    add_filter('pre_get_posts', 'ag_custom_post_type_order');

  • WordPress ユーザー権限毎にエクスポートできるプラグイン

    User Export (with their Meta Data)

    ユーザー権限毎にユーザー情報をエクスポートできる便利なプラグイン

  • Google マップで「maps.google.co.jp で接続が拒否されました。」と表示される。

    Google マップで「maps.google.co.jp で接続が拒否されました。」と表示される。

    maps.google.co.jp で接続が拒否されました。

    2021年5月25日-26日ころにかけてGoogle mapをiflameを使って表示しているページで「maps.google.co.jp で接続が拒否されました。」というエラーメッセージと共に地図が表示されない現象が起こった。(※ちなみに現在は正常通り表示されている・・・・)

    よく調べてみるとiframeで埋め込みマップパラメーター(引数)を使用している地図だけエラーとなっているようだ。

    例えば、?q=住所 などで地図を表示させているケース。

    このマップパラメーターは、実は非公式で、いつ使えなくなってもおかしくなかった模様。

    現在はGoogle map apiを取得することで同等のことが可能となる。

    クレジットカード情報などを入力する必要があるが、「?q=住所」のような住所や施設名を指定して地図を表示させるだけなら、引き続き無料で実現できる。

    アクセス数に応じた課金制度に関しては随時更新されているので以下の公式ページから金額を要確認。

    https://developers.google.com/maps/billing/gmp-billing#maps-product

    Google map APIの設定に関しては以下のページの説明がわかりやすい。

    https://www.zenrin-datacom.net/business/gmapsapi/api_key/

    Google map API 設定時の注意点

    「アプリケーションの制限」で使用するサイトやアプリからのアクセスに制限し、API KEYを悪用されないようにする。

    アプリケーションの制限では、API キーを使用できるウェブサイト、IP アドレス、アプリケーションを制御できます。アプリケーションの制限はキーごとに 1 つ設定できます。

  • WordPress ページ速度向上のためにできること

    サイトスピードを向上させるために・・・・

    JSを圧縮

    https://syncer.jp/js-minifier

    CSSを圧縮

    http://www.creativyst.com/Prod/3/

    Jqueryはホスト化されたものを使う

    https://developers.google.com/speed/libraries/#jquery

  • Elementorで権限毎にwidgetを非表示にする方法

    Elementorで権限毎にwidgetを非表示にする方法

    // GET CURRENT USER ROLE
    function get_current_user_role() {
    if( is_user_logged_in() ) {
    $user = wp_get_current_user();
    $role = ( array ) $user->roles;
    return $role[0];
    } else {
    return false;
    }
    }

    // Remove the Elementor Widgets from the left-hand Panel in the Live Editor

    global $elementor_widget_blacklist;

    $elementor_widget_blacklist = [
    // FREE
    ‘read-more’,
    ‘sidebar’,
    ‘audio’,

    // PRO
    ‘posts’,
    ‘portfolio’,
    ‘slides’,
    // ‘form’,
    ‘login’,
    ‘media-carousel’,
    ‘testimonial-carousel’,
    ‘nav-menu’,
    ‘pricing’,
    ‘facebook-comment’,
    ‘nav-menu’,
    ‘animated-headline’,
    ‘price-list’,
    ‘price-table’,
    ‘facebook-button’,
    ‘facebook-comments’,
    ‘facebook-embed’,
    ‘facebook-page’,
    ‘add-to-cart’,
    ‘categories’,
    ‘elements’,
    ‘products’,
    ‘flip-box’,
    ‘carousel’,
    ‘countdown’,
    ‘share-buttons’,
    ‘author-box’,
    ‘breadcrumbs’,
    ‘search-form’,
    ‘post-navigation’,
    ‘post-comments’,
    ‘theme-elements’,
    // ‘blockquote’,
    ‘template’,
    ‘wp-widget-audio’,
    ‘woocommerce’,
    ‘social’,
    ‘library’,
    ‘reviews’,
    ‘gallery’,
    ‘table-of-contents’,
    ‘html’,
    ‘star-rating’,
    ‘sitemap’,
    ‘theme-site-logo’,
    ‘theme-site-title’,
    ‘theme-page-title’,
    ‘theme-post-title’,
    ‘theme-post-excerpt’,
    ‘post-info’,
    ‘theme-post-featured-image’
    ];

    // CHECK CURRENT USER ROLE AND EXECUTE RESTRICTION IF NEEDED (in thix exemple for editor role)

    if( is_admin() && get_current_user_role() == ‘editor’) {

    // Remove all the Elementor Free & Pro Widgets listed above
    add_action(‘elementor/widgets/widgets_registered’, function($widgets_manager){
    global $elementor_widget_blacklist;
    foreach($elementor_widget_blacklist as $widget_name){
    $widgets_manager->unregister_widget_type($widget_name);
    }
    }, 15);

    // Remove the regular WordPress Widgets from the left-hand Panel in the Live Editor
    if ( ! function_exists( ‘ddw_tweak_elementor_remove_wp_widgets’ ) ) :
    add_filter( ‘elementor/widgets/black_list’, ‘ddw_tweak_elementor_remove_wp_widgets’ );

    function ddw_tweak_elementor_remove_wp_widgets( $black_list ) {
    /** Bail early if Elementor not active or tweak not wanted */
    if ( ! defined( ‘ELEMENTOR_VERSION’ ) ) {
    return $black_list;
    }

    /**
    * Get all registered WordPress widgets, but only the classes
    * (= the first-level array keys)
    */
    $black_list = array_keys( $GLOBALS[ ‘wp_widget_factory’ ]->widgets );

    /** Return black list array for filter */
    return (array) $black_list;

    }
    endif;

    }

  • WordPressカテゴリーページで説明を表示する方法

    カテゴリーページで説明を読み込み出力方法をメモ。

    <?php if(!is_paged()):?>
    <?php if(category_description()):?>

    <?php echo category_description(); ?>

    <?php endif;?>

    一行目はカテゴリーページが数ページある場合に1ページ目にだけに出力るための条件分岐。

  • EmEditor ワイルドカードで置換

    htmlタグから classを全部取り除きたいとき。

    .*? がワイルドカードとして使える

    テキストエディタで正規表現検索で、class= .*?> を検索し > に変換すればOK

  • WordPress キャッチアイ画像を背景画像にするCSS PHP

    <section class="" style="background-image: url(<?php echo get_the_post_thumbnail_url( get_the_ID(), 'learge' );?> )!important;">

  • Bootstrap4 card-columnsのbreakpointsを変更し表示card数を変更する方法

    Bootstrap4ではMasonryのような表示を可能にする.card-columns が加わった。

    https://getbootstrap.jp/docs/4.2/components/card/

    Responsiveに対応しているのだが、Breakpointブレークポイントを変更する方法が掲載されていなかったのでメモ。

    Cssで簡単に変更することができる。

    CSSでBootstrap4 card-columnsのbreakpointsを変更

    @media (min-width: 576px) {
        .card-columns {
            column-count: 2;
        }
    }
    @media (min-width: 768px) {
        .card-columns {
            column-count: 3;
        }
    }
    @media (min-width: 992px) {
        .card-columns {
            column-count: 4;
        }
    }
    @media (min-width: 1200px) {
        .card-columns {
            column-count: 5;
        }
    }
    

    SASSでBootstrap4 card-columnsのbreakpointsを変更

    .card-columns {
      @include media-breakpoint-only(xl) {
        column-count: 5;
      }
      @include media-breakpoint-only(lg) {
        column-count: 4;
      }
      @include media-breakpoint-only(md) {
        column-count: 3;
      }
      @include media-breakpoint-only(sm) {
        column-count: 2;
      }
    }