LoginSignup
1
2

More than 5 years have passed since last update.

WordPressでテーマのテンプレートファイルではなくプラグインなどから任意のファイルを読み込ませる

Posted at

テーマ本体をさわるんじゃなくてプラグインからごにょごにょしたいけど、
テーマ本体にフック用意されてねーし!

って時に強制的に上書きしたい時って、あるよね!

function my_custom_template_file() {
    if ( get_post_type() == 'post' && is_single() ) {
        // 読み込ませたいファイルを指定
        require( 'template-parts/doc/frame-salary-archive.php' );
        die();
    }
}
add_action( 'template_redirect', 'my_custom_template_file' );

たぶん die(); じゃなくて他の関数使えよ!とか、
こんな方法の方がセオリーだよ!
ってのがあったらコメントください!

1
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
1
2