I have enqueue a stylesheet into a plugin I built. When I load the page I can see that there is a link tag created linking to my stylesheet. I can view the stylesheet in chrome's source
tab. However the class is not applied to my element.
My Element without it's class being applied
Header showing the link to my style sheet
Source tab showing the stylesheet
I've added this line to the top of my file to make sure that the stylesheet is enqueued before the subsequent html is rendered
<?php echo wp_style_is($this->product_controller->plugin_name) ? 'enqueued' : 'nope'; ?>
this always echos out 'enqueued'
when my class is instantiated this function runs. This calls the function on whatever controller is passed in.
private function add_default_actions($controller, $classname)
{
$prefixed_name = "pp_" . $classname;
$this->loader->add_action( 'admin_enqueue_scripts', $controller, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $controller, 'enqueue_scripts' );
//when a request is made to to admin-ajax.php
$this->loader->add_action( 'wp_ajax_' . $prefixed_name, $controller, 'ajax_handler');
$this->loader->add_action( 'wp_ajax_' . $prefixed_name, $controller, 'check_nonce');
}
this is the function that gets run in my $controller
public function enqueue_styles()
{
$location = plugin_dir_url( __FILE__ ) . 'css/'. $this->classname .'.css';
wp_enqueue_style( $this->plugin_name, $location, array(), $this->version, 'all' );
}
I'm trying to turn a h2
tag blue so that I know my styles is getting rendered and my browser is like, nope.
答案 0 :(得分:0)
问题是我将其称为./src/index
而不是classname
。这样就解决了。
我使用javascript的时间太长了。