Read below if you want to start from where I left off in core. But the basic question is: I need to add a “title” attribute to my stylesheets and wp_enqueue_style() doesn’t allow for that parameter, as far as I can tell. Other than a hard embed, are there any ways WordPress allows us to add the title to a stylesheet?

In digging around core I notice that there’s a $title variable that can be set using $style->extra['title'].

$title = isset($this->registered[$handle]->extra['title']) ? "title="" . esc_attr( $this->registered[$handle]->extra["title'] ) . "'" : '';

(class.wp-styles.php)

And $title also figures in the filter that is applied when you enqueue a stylesheet. So how can you set that ‘extra’ array within the style object?

4 s
4

Okay, here’s where I’m at with a solution.

wp_enqueue_style( 'my-handle', 'mystyle.css' );
global $wp_styles;
$wp_styles->add_data( 'my-handle', 'title', 'my_stylesheet_title' );

Don’t like using the global. Is there something better?

Leave a Reply

Your email address will not be published. Required fields are marked *