現在やろうとしてること
WordPressで自作プラグインにその中で適用できるcssを読み込ませたい。
こちらの記事には答えらしきものがありますが、これ通りにしてもスタイルが当たってくれません。
ディレクトリ構成
custom-field |- custom-field.php |- css |- form.css
php
1<?php 2/* 3Plugin Name: custom-field 4Plugin URI: http://www.example.com/plugin 5Description: This is Plugin Test. 6Author: Name 7Version: 1.0 8Author URI: http://www.example.com 9*/ 10 11if (! defined('ABSPATH')) { 12 exit; 13} 14 15// 記事通りに記述 16// 本来ならこれでスタイルが読み込まれるはず 17add_action('wp_enqueue_script','register_my_scripts'); 18function register_my_scripts(){ 19 $dir = plugin_dir_path( __FILE__ ); 20 wp_enqueue_style( $dir . 'css/form.css'); // ここは変更 21} 22 23// カスタムフィールドのメタボックス 24function add_custom_fields() { 25 add_meta_box('id', '独自カスタムフィールド(通常投稿)', 'insert_custom_fields', 'post', 'normal'); // postにすると通常投稿に追加 26} 27add_action('admin_menu', 'add_custom_fields'); 28 29// post投稿の入力エリア 30function insert_custom_fields() { 31 global $post; 32 33 // テキスト この場所に独自のスタイルを当てたい 34 echo ' 35 <div> 36 <p>タイトル</p> 37 <input type="text" name="title" value="'.get_post_meta($post->ID, 'title', true).'" /> 38 </div>'; 39} 40 41// カスタムフィールドの値を保存 42function save_custom_fields($post_id) { 43 if (!empty($_POST['title'])) { 44 update_post_meta($post_id, 'title', $_POST['title']); 45 } 46} 47add_action('save_post', 'save_custom_fields'); 48
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/16 01:14