WordpressでStorefrontというテーマから子テーマを作成し、
子テーマのフォルダにfunctions.phpファイルを内包しました。
ヘッダの部分に簡易的なログインボタンを設け、クリックすると該当するログインページへリンクするという仕組みを作りたく、
Storefrontのheader.phpに書かれているstorefront_headerというアクションフックに対し、
前述の子テーマフォルダに内包のfunction.phpに
function loginform_righttop() { echo '<button type="submit" onclick="location.href='./my-account'">ログイン</button>'; } add_action( 'storefront_header', 'loginform_righttop', 35 );
と記述したのですが、
Parse error: syntax error, unexpected '/'
と、エラーが表示されてしまいます。
また、
<?php /** * Functions hooked into storefront_header action * * @hooked storefront_header_container - 0 * @hooked storefront_skip_links - 5 * @hooked storefront_social_icons - 10 * @hooked storefront_site_branding - 20 * @hooked storefront_secondary_navigation - 30 * @hooked storefront_product_search - 40 * @hooked storefront_header_container_close - 41 * @hooked storefront_primary_navigation_wrapper - 42 * @hooked storefront_primary_navigation - 50 * @hooked storefront_header_cart - 60 * @hooked storefront_primary_navigation_wrapper_close - 68 */ do_action( 'storefront_header' ); ?>
上記のphpで書かれている部分の直前に
<button type="submit" onclick="location.href='./my-account'">ログイン</button>
というコードを挿入すると正しくボタンが表示され、機能するのですが、この違いは何なのでしょうか
echoでhtmlを埋め込んだ場合、onclick属性は機能しないのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/30 15:18