简体   繁体   中英

Wordpress - Use CSS in Plugin

i wrote a CSS plugin for TinyMCE to add a new button to the editor's menubar. I click on the button and a popup opens, the content - written in JS - looks like this:

var form = jQuery('<div id="a2ml-form">\ <div
class="a2ml-form-selector">Landingpage Quiz</div>\ <div
class="a2ml-form-selector">AR Quiz</div>\ </div>');

I want to use the class="a2ml-form-selector" - but the CSS which i applied with this code:

function add_to_head() {
    $url = trim(get_bloginfo('url'), "/");
?>
    <link rel="stylesheet" type="text/css" href="<?=$url?>/wp-content/plugins/a2m_landingpages/a2m_landingpages.css">
<?
}

add_action('wp_head', 'add_to_head');

is not loaded into the wp-admin panel - it is loaded to the mainsite. How can use CSS styles in the admin-panel?

Thanks

You really shouldn't be writing out your own link tags like that. You should be using the admin_enqueue_scripts hook:

function load_custom_wp_admin_style() {
    wp_register_style( 'a2m_landingpages_css', plugin_dir_path( $plugin_filename ) . '/a2m_landingpages/a2m_landingpages.css', false, '1.0.0' );
    wp_enqueue_style( 'a2m_landingpages_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

You might be able to get away with:

add_action('admin_enqueue_scripts', 'add_to_head');

but it's not the best way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM