前提・実現したいこと
script.jsとstyle.cssのファイルをwordpressに読み込ませたい
該当のソースコード
function.phpに書きました。
php
function add_my_files() { wp_enqueue_script( 'my-script', get_theme_file_uri( '/script.js' ), array(), filemtime( get_theme_file_path( '/script.js' ) ), true ); //スタイルシートの読み込み wp_enqueue_style( 'my-style', get_theme_file_uri( '/style.css' ), array(), filemtime( get_theme_file_path( '/style.css' ) ) ); } add_action('wp_enqueue_scripts', 'add_my_files');
ファイル
header.php
php
<!DOCTYPE html> <html lang="jp"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <?php wp_head(); ?> </head> <body> <header> </header
footer.php
php
<footer> </footer> <?php wp_footer(); ?> </body> </html>
index.php
php
<?php get_header() ;?> <aside> <h1>こんにちは</h1> <h2>日本語で</h2> <h5>ヨロシク</h5> </aside> <?php get_footer() ;?>
試してみたこと
cssで色、javascriptでconsoleに表示の指定をしてみました。
style.css
css
body{ background-color: blue; }
script.js
javascript
console.log("正解");
色もconsoleにも表示されませんでした。
何が原因なのか教えてください。
お願いします。
補足情報(FW/ツールのバージョンなど)
使用しているeditor
VSCord(バージョン: 1.60.2 )
FTPソフト
File Zilla
レンタルサーバー
conoha
参考サイト
まだ回答がついていません
会員登録して回答してみよう