考虑以下 WordPress 插件代码:
<?php
/**
* Plugin Name: test
* Description: This plugin is just a test for bootstrap css
* Version: 1.0.0
* Author: Gavin Simpson
* License: GPL2
*/
class testclass
{
private static $instance;
public static function get_instance_advert()
{
if( null == self::$instance )
{
self::$instance = new testclass();
}
return self::$instance;
}
private function __construct()
{
add_action( 'admin_enqueue_scripts', array($this,'inistyleheets'));
}
function inistyleheets()
{
wp_register_style( 'mybootstrap', plugins_url() . '/test/assets/bootstrap-3.3.5-dist/css/bootstrap.min.css');
wp_enqueue_style('mybootstrap');
}
}
add_action( 'plugins_loaded', array( 'testclass', 'get_instance_advert'));
?>
激活上述内容后,Wordpress 管理中的“屏幕选项”按钮将停止工作。
问题 100% 与仅加载 Bootstrap css 有关,因此该示例不会加载 bootstrap 本身。在我的生产代码中, Bootstrap 工作得很好,它只是破坏了所描述的“屏幕选项”按钮,就像上面的基本插件代码一样。
我已经尝试了所有基本主题,即二十四、二十五和二十六。他们中的任何一个都不走运,结果都一样。
最佳答案
冗长的解决方案,所以这里不再重复,但链接是 https://rushfrisby.com/using-bootstrap-in-wordpress-admin-panel 。 (是的,我知道发布链接并不酷,但我不想复制并粘贴别人的解决方案)
底线是,您需要包装您可能想要添加 Bootstrap CSS 的任何代码,上面链接中的解决方案负责以一种非常有效的方式加载 Bootstrap。
关于php - 为什么 bootstrap 会破坏 WordPress 管理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36272728/