32.wordpressにgoogleサイト内検索formを設置

作成日: 2022/08/16 更新日: 2023/03/25 サイトの紹介と使い方

初めに

  1. function Codeの分類、構成は、筆者が独自に行っています。
  2. googleが用意したサイト内検索のフォームをWordpressに設置します。
  3. ファイル(置き場所):テーマCocoon childのfunctions.php
  4. 分類コード:22xx

内容

説明

  1. 機能:サイト内検索のフォームを構成するHTMLを文字列として返します。
  2. 引数:無し
  3. 戻り値:HTML戻り値
    1. 11.google検索でサイト内検索を行うを参照してください。
      このfunctionは、上の記事と同じ内容を戻り値として返します。

ソースコード

//<--- 2202
function my_search_form_parts($atts){
  $ret  = "<form class=\"my-search-site\" method=\"get\" action=\"https://www.google.co.jp/search\" target=\"_blank\">";
  $ret .= "<input type=\"hidden\" name=\"sitesearch\" value=\"";
  $ret .= my_get_domain();
  $ret .= "\">";
  $wrk  = urldecode( "%E3%82%AD%E3%83%BC%E3%83%AF%E3%83%BC%E3%83%89%E3%82%92%E5%85%A5%E5%8A%9B%E3%81%97%E3%81%A6%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84" );
  $ret .= "<input type=\"text\" name=\"q\" style=\"font-size:15px;size:20px;\" placeholder=" . $wrk . " value=\"\">";
  $wrk  = "google" . urldecode( "%E3%82%B5%E3%82%A4%E3%83%88%E5%86%85%E6%A4%9C%E7%B4%A2" );
  $ret .= "<button type=\"submit\" style=\"height:40px;font-weight:bold;\">" . $wrk . "</button>";
  $ret .= "</form>";
	
  my_debug_shortcode_echo( "my_search_form.txt",$ret );

  return $ret;
}
// 2202 --->

CSS

/* ---> 0103 google サイト内検索フォーム */
.my-search-site{
  position: absolute;
  top:      5.0rem;
  left:     15.0rem;
}
/* <--- 0103 */

お問合せ・御要望

お問合せ
Verified by MonsterInsights
タイトルとURLをコピーしました