カテゴリー: WordPress

  • Customize Style Contact Form 7 on WordPress

    What is this?

    I’ve edited the CSS for Contact Form 7, a popular WordPress plugin for creating contact forms.

    When implemented, it looks like this:


    A small detail I focused on was adding an ease effect to the focus state.


    How to Apply Styles to Contact Form 7

    First, add Contact Form 7 as a new plugin.

    Download Contact Form 7

    Once installed and activated, you should see a new “Contact” item in the left sidebar of your WordPress dashboard. Click on it.


    When you open it, you’ll likely see a form that has already been added. Open that form.


    In the form editor, paste the following code (feel free to copy-paste):


    The code is based on the classes and elements from the official Contact Form 7 site. I’ve styled it in a way that minimally changes the default settings upon installation.

    <label class="form__label"> 企業名
        [text* your-name class:form__textInput autocomplete:name] </label>
    
    <label class="form__label"> お名前
        [text* your-name class:form__textInput autocomplete:name] </label>
    
    <label class="form__label"> メールアドレス
        [email* your-email class:form__textInput autocomplete:email] </label>
    
    
    <label class="form__label"> お問い合わせ内容
        [textarea* your-message class:form__textInput] </label>
    
    [submit "Submit"]
    
    <style>
    .form__container {
      max-width: 400px;
      margin:0 auto;
    }
    
    .form__label {
      display: block;
      margin-top:1.5em;
      color: gray;
      font-size: 0.8em;
    }
    
    
    
    .form__textInput {
      width: calc(100% - 2.4em);
      border: 1px #c0c0c0 solid;
      border-radius: 2px;
      padding: 1em 1.2em;
      color: 1e1e1f;
    }
    
    .form__textInput:focus {
      transition: .3s ease-out;
      outline: 1px skyblue solid;
    }
    
    .wpcf7-submit {
      display: block;
      color: white;
      background-color: black;
      padding: 0.8em 2em;
      border-radius: 4px;
      margin: 2em auto;
      border: none;
    }
    
    .wpcf7-submit:active {
      background-color: rgb(95, 95, 95);
      /* This style is created by https://coiai.boy.jp */
    }
    </style>


    Once the form setup is complete, navigate to a static page where you want to add the form.


    Here’s an example of how it looks when added.


    I’ve kept the code minimal, avoiding unnecessary things like titles, background color settings, or size restrictions. Feel free to adjust it to suit your environment.

  • Contact Form 7 の見た目を綺麗にする HTML CSS コピペOK

    これは何?

    WordPressの定番のお問い合わせ用プラグインのcontact form 7 のCSSを編集しました。

    実装すると以下のようになります。

    focus に少しease を入れるのがこだわり

    コンタクトフォーム7にスタイルを適応する方法

    プラグインからcontact form 7を新規追加します。

    インストールして有効化すると左サイドバーに Contact という項目ができていると思うので、クリックします。

    開くと、すでに追加されているフォームがあると思いますので、
    そちらを開きます。

    開いたら、編集画面になりますので以下のコードを貼り付けます(コピペOK)

    コードは contact form 7 の公式サイトを頼りにクラスなどの指定をしました。
    なるべくインストール時の標準の状態を崩さずにスタイリングしています。

    <label class="form__label"> 企業名
        [text* your-name class:form__textInput autocomplete:name] </label>
    
    <label class="form__label"> お名前
        [text* your-name class:form__textInput autocomplete:name] </label>
    
    <label class="form__label"> メールアドレス
        [email* your-email class:form__textInput autocomplete:email] </label>
    
    
    <label class="form__label"> お問い合わせ内容
        [textarea* your-message class:form__textInput] </label>
    
    [submit "Submit"]
    
    <style>
    .form__container {
      max-width: 400px;
      margin:0 auto;
    }
    
    .form__label {
      display: block;
      margin-top:1.5em;
      color: gray;
      font-size: 0.8em;
    }
    
    
    
    .form__textInput {
      width: calc(100% - 2.4em);
      border: 1px #c0c0c0 solid;
      border-radius: 2px;
      padding: 1em 1.2em;
      color: 1e1e1f;
    }
    
    .form__textInput:focus {
      transition: .3s ease-out;
      outline: 1px skyblue solid;
    }
    
    .wpcf7-submit {
      display: block;
      color: white;
      background-color: black;
      padding: 0.8em 2em;
      border-radius: 4px;
      margin: 2em auto;
      border: none;
    }
    
    .wpcf7-submit:active {
      background-color: rgb(95, 95, 95);
      /* This style is created by https://coiai.boy.jp */
    }
    </style>

    フォームの入力が完了したら、固定ページに移動して追加しました。

    次の画像のような感じで追加しています。

    コード自体にはタイトルや背景色指定、サイズ制限などの余計なことはなるべくしないようにしました。お使いの場合は適宜環境に合わせてお使いください。

  • “Saving failed” WordPress Theme Customize

    When customizing a theme in WordPress, you may sometimes encounter error messages in a red frame such as “Saving failed,” “Update failed. The response is not a valid JSON response,” and “Saving failed.”

    This post will explain how to resolve this issue as of September 2024.

    How to Resolve the “Saving Failed” Error

    I encountered this error when using WordPress’s default theme called Twenty Twenty-Four. It only appeared when I tried saving from the template customization screen.

    For Users of Onamae.com OR something rental server

    If you are using Onamae.com, the WAF security setting might be turned ON in the Onamae.com control panel. Try turning it OFF.

    To do this, access the rental server control panel:
    https://cp.onamae.ne.jp/homepagesecurity/waf

    In the left side panel, under Homepage Settings/Security, select the WAF option and turn off the Detection Log Management setting.

    For Users of Security Plugins

    If you are using a security plugin in WordPress, such as the “SiteGuard” plugin, which has a WAF security setting, you can turn it OFF from the plugin’s settings page.

    If This Does Not Solve the Issue

    If the issue persists after these steps, feel free to leave a comment. I might be able to help further.


    What is WAF Security?

    WAF (Web Application Firewall) is a security system designed to protect web applications from unauthorized access or attacks.

    WAF plays a role in detecting and preventing application-level attacks. Specifically, it can detect attacks such as SQL injection, cross-site scripting (XSS), and malicious HTTP requests, blocking them before they reach the web application.

    WAF is deployed at the boundary of the network. While a traditional firewall mainly protects the network layer, WAF monitors the communication to and from web applications, identifying attack patterns.

    By implementing WAF, you can improve the security of publicly accessible web services and applications.

    Types of WAF:

    • Host-based WAF: Installed directly on the server, placed on each web server.
    • Cloud-based WAF: Delivered through the cloud, it prevents attacks on web applications over the internet.

    Introducing WAF can reduce the risk of data leaks or service outages caused by unauthorized access or attacks, making it a crucial security measure.


    How WAF Works:

    WAF is positioned between the web server and the internet, and it protects web applications through the following flow:

    1. Traffic Monitoring: WAF monitors HTTP/HTTPS traffic sent to the web application in real-time.
    2. Rule-based Inspection: WAF comes preconfigured with rule (signature) sets that detect common attack patterns and threats. Traffic is inspected against these rules.
      • Examples: SQL injection, cross-site scripting (XSS), file upload attacks, etc.
    3. Attack Detection and Blocking: When a request shows signs of an attack, WAF blocks the request and prevents the attack. Additionally, it can log details of the attack and notify administrators.
    4. Allowing Normal Requests: Requests that do not violate the rules are allowed to reach the web server, and the application operates as usual.

    Reference:

    https://siteguard.jp-secure.com/blog/what-is-owasp

  • お名前.com WordPress で”保存に失敗しました”のエラーが出る

    これは何?

    WordPressでテーマをカスタマイズしている際に下記の画像のように、
    「保存に失敗しました」「更新に失敗しました。 返答が正しい JSON レスポンスではありません。」「Saving failed.」
    と入った赤い枠でエラーメッセージが出る場合があります。

    今回はそれの解決方法についてです。

    この記事は2024年9月現在確認済みです。


    “保存に失敗しました”の解決方法

    このエラーが出たのはワードプレスの Twenty Twenty-Four というデフォルトのテーマを使っていた時です。
    テンプレートのカスタマイズの画面から保存した時のみこのようなエラーが出ました。

    お名前.comを契約の方

    お名前.comを使用している方は、お名前ドットコムの管理画面の方でWAFセキュリティ設定がONになっている場合があります。
    こちらをOFFにしてみましょう。

    設定方法はレンタルサーバーコントロールパネルにアクセスします。
    https://cp.onamae.ne.jp/homepagesecurity/waf
    左サイドパネルにホームページ設定/セキュリティの項目があるので、そちらを選択後、
    WAFの項目をタップし、検知ログ管理の設定をOFFにしましょう。

    セキュリティ系プラグインをお使いの方

    ワードプレスのプラグインで、”SiteGard”というプラグインをはじめWAFセキュリティ設定があるものがあります。
    こちらをプラグインの設定画面からOFFにしてあげれば大丈夫です。

    これで解決しない場合

    これで解決しない場合はコメントください。もしかしたらお力になれるかも?しれません。


    WAF セキュリティ設定とは何か?

    WAF(Web Application Firewall)は、Webアプリケーションへの不正アクセスや攻撃から保護するためのセキュリティシステムです。

    WAFは、アプリケーションレベルの攻撃を検知して防御する役割を果たします。
    具体的には、SQLインジェクション、クロスサイトスクリプティング(XSS)、不正なHTTPリクエストなどの攻撃を検出し、
    Webアプリケーションに到達する前にブロックします。

    WAFはネットワークの境界に設置され、通常のファイアウォールが主にネットワーク層の通信を保護するのに対し、
    WAFはWebアプリケーションの通信を監視し、攻撃パターンを識別します。

    導入することで、特に公開されているWebサービスやアプリケーションのセキュリティを向上させることができます。

    WAFの種類としては、次のようなものがあります:

    • ホスト型WAF:サーバー内にインストールされるWAFで、各Webサーバーに直接配置されます。
    • クラウド型WAF:クラウドベースで提供され、インターネット経由でWebアプリケーションへの攻撃を防ぎます。

    導入することで、不正アクセスや攻撃によるデータ流出やサービス停止のリスクを軽減できるため、重要なセキュリティ対策の一つとされています。

    仕組み

    仕組み

    WAFは、Webサーバーとインターネットの間に位置し、以下のような流れでWebアプリケーションを保護します。

    1. 通信の監視: WAFは、Webアプリケーションに向かって送信されるHTTP/HTTPSトラフィックをリアルタイムで監視します。

    2. ルールに基づく検査: WAFには、一般的な攻撃パターンや脅威に対するルール(署名)セットが事前に設定されており、トラフィックがこれらのルールに基づいて検査されます。

    : SQLインジェクション、クロスサイトスクリプティング(XSS)、ファイルアップロード攻撃など。

    3. 攻撃の検出とブロック: 攻撃の兆候があるリクエストが検出されると、WAFはそのリクエストをブロックし、攻撃を未然に防ぎます。さらに、攻撃の詳細をログに記録して管理者に通知することも可能です。

    4. 正常なリクエストは許可: ルールに違反しない正常なリクエストはWebサーバーに到達し、通常通りアプリケーションが動作します。

    参考サイト様

    https://siteguard.jp-secure.com/blog/what-is-owasp

  • WordPress にGoogle Tag Mnager を設定する方法

    Google Tag Mnagerこれは何?

    WordPress にGoogle Tagmanager (GTM)を設定する方法についてです。

    サードパーティー製のプラグインの使用やコードをいじる必要はありません!

    この記事は2024年9月現在の仕様です。

    Tag Mnager の設定手順

    WordPressの管理画面に入り、
    Google Site Kit プラグインを有効化しましょう。

    SiteKitを有効化すると、Goolgleアカウントの連携についての画面が開きますので、アカウントを設定して、指示に従って進めます。

    設定が完了すると、ダッシュボードが開きます。

    設定当日から1-2日はダッシュボードが空白だと思いますが、準備が完了するとデータが見られるようになります。

    管理画面 Site Kit のダッシュボード

    プラグインの有効化ができたら、左サイドメニューの Site Kitの下に [設定]の項目があるので、そちらをクリックします。

    Connected Services, Connect More Services, Admin Settings という3つのタブがあるので、
    [Connect More Services]を押します。

    ここで[Set up タグマネージャー]ボタンを押します。
    タグマネージャのアカウントを今まで設定したことがなければ[Create an account]を押しましょう。

    そうすると新しいタブで https://tagmanager.google.com にアクセスされるはずです。

    アカウント名、国を入力します。

    コンテナセットアップの項目は

    • コンテナ名 → 自分のサイトの名前
    • ターゲットプラットフォーム → Web

    を入力、選択しましょう。

    入力したら[Create]ボタンを押して、利用規約に同意します。

    設定が完了すると、 Install Google Tag Mnager のポップアップが表示されますが、今回はWordPressを使うので閉じて大丈夫です。

    ここまできたら、またWordPressの管理画面に戻ります。

    SiteKitの設定のページに移動すると、[Complete setup for Tag Mnager]のボタンが表示されているので押します。

    そしたら先ほど制作した、アカウント名とコンテナ名が選択できるので選択肢、[Complete setup]ボタンを押しましょう。

    これでWordPressに設定が完了しました。

    まとめ

    以上WordPressにTagMnagerを設定する方法でした。

    ここまでで設定が完了したのですが、タグマネージャーを使いこなすにはGoogleアナリティクスとの連携やボタン押下のトラッキングを設定する必要があります。

    それについては別記事で解説しているので見てみてください。

    https://coiai.boy.jp/1963/
  • lolipop SSH で接続して WP-Cli を使う

    ❓ これは何

    データベースのバックアップからJpegからWebPへの変換など、
    WP-Cliを使えばスムーズにできることがあります。

    今回はロリポップや、さくらインターネット、Xサーバーなどの
    レンタルサーバーを使用している方向けに、
    SSHで接続して、WP-Cli を使う方法を紹介します。

    この記事は2024年8月22日現在実行確認しました。

    🪴 環境

    サーバー側

    • php 8.2
    • WP-CLI 2.11.0

    使用PC

    • Apple Silicon m1
    • sonoma 14.5

    🖐️ 手順

    1 レンタルサーバーにSSH接続

    まずはターミナルを開いてSSHでサーバーに接続します。

    ロリポップを使用の場合は下記のサポートページをみながらSSH接続してみましょう。
    https://lolipop.jp/manual/user/ssh-m-terminal

    2 PHP の設定

    SSHで接続したらphpを確認します。

    php -v

    しかし、このコマンドでは command not found になってしまします。

    /usr/local/php/8.2/bin/php -v

    これで実行できますが、不便すぎます。

    以下の記事を参考に設定しました。
    https://qiita.com/yuuki_okubo/items/54f62f7acb94e273bd96

    vi ~/.bash_profile

    .bash_profile の中身は下記のように変更する。

    if [ -f ~/.bashrc ]; then
       source ~/.bashrc
    fi
    
    export PATH="~/bin:$PATH"
    source .bash_profle

    以下コマンドでパスを設定します。

    echo 'export PATH=/usr/local/php/8.2/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc

    これで php -v の実行ができるようになります。

    3 wp-cli の設定

    公式ページを参考にやってみます。
    https://wp-cli.org/ja

    web と同じ階層に binディレクトリを作成し,
    bin ディレクトリへ移動します。

    mkdir bin
    chmod 705 bin/
    cd bin

    wp-cli を curl を使ってインストールします。

    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

    追加したファイルの権限を変更をし、wp-cli.phar を wpとします。

    chmod 705 wp-cli.phar 
    mv wp-cli.phar wp

    インストールが出来たかは下記コマンドで確認できます。

    wp --info

    以上です。