I would like to create a WordPress Plugin to add some css of a website, the css only takes effected when the plugin is activated. Is there any good idea? Is there any documentation I can take to get help?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to create a wordpress plugin, you need to follow Plugin Handbook, there is the link: https://developer.wordpress.org/plugins/.
You can create a CSS file in plugin directory then upon plugin activation hook, you can enqueue the CSS file using action ‘wp_enqueue_style’.
Please add this to your main file in order to load your css file:
function add_my_css() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'style', $plugin_url . "/css/plugin-style.css");
}
add_action( 'wp_enqueue_scripts', 'add_my_css' );
Finally you can create the plugin-style.css file and start to write your own css file.