LoginSignup
4
3

More than 5 years have passed since last update.

WordPress の functions.php 内に独自 Class を書く

Posted at

WordPress の functions.php 内に独自 Class を書く場合は、new する前に global で定義しないと読み込めません。当然、呼び出す側(header.php など)でも global で定義しないといけません。

<?php
class Hoge {
    public $fuga = 'Qiita';
}
global $hoge;
$hoge = new Hoge();
<?php
global $hoge;
echo $hoge->fuga;

もっといいやり方があったら教えてください(・∀・)

4
3
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
4
3