LoginSignup
2
2

More than 5 years have passed since last update.

Wordpress functions.php内で使っている変数をJSで使いたいとき

Posted at

javascriptから使いたい時がたまにあるのでメモ

e.g. functions.phpのget_currentuserinfoをJSで使いたいとき

functions.php
function functionsInfoToJs() {
  get_currentuserinfo();
  global $user_level;
  echo '<script type="text/javascript">var _g_user_level = "' . $user_level . '";</script>';  // JS内はよしなに
}
// 管理画面内に出力
//add_action( 'admin_print_scripts', 'functionsInfoToJs' );
// 全体の画面内に出力
add_action( 'wp_print_scripts', 'functionsInfoToJs' );
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2