The get_editor_stylesheets() WordPress PHP function retrieves any registered editor stylesheet URLs.
Usage
Here’s a generic example of using the function to fetch and print the editor stylesheets:
$stylesheets = get_editor_stylesheets();
foreach ($stylesheets as $stylesheet) {
echo 'Stylesheet URL: ' . $stylesheet . '<br>';
}
Parameters
- There are no parameters for this function.
More information
See WordPress Developer Resources: get_editor_stylesheets()
Examples
Display registered editor stylesheets in a list
This example prints out registered editor stylesheets as an HTML unordered list.
$stylesheets = get_editor_stylesheets();
echo '<ul>';
foreach ($stylesheets as $stylesheet) {
echo '<li>' . $stylesheet . '</li>';
}
echo '</ul>';
Add editor stylesheets to a custom meta box
This example adds a meta box displaying the editor stylesheets in the post editor.
function custom_meta_box() {
add_meta_box('editor-styles', 'Editor Stylesheets', 'display_editor_styles');
}
add_action('add_meta_boxes', 'custom_meta_box');
function display_editor_styles() {
$stylesheets = get_editor_stylesheets();
echo '<ul>';
foreach ($stylesheets as $stylesheet) {
echo '<li>' . $stylesheet . '</li>';
}
echo '</ul>';
}
Check if a specific stylesheet is registered
This example checks if a specific stylesheet is registered as an editor stylesheet.
function is_editor_stylesheet($url) {
$stylesheets = get_editor_stylesheets();
return in_array($url, $stylesheets);
}
$stylesheet_url = 'https://example.com/my-stylesheet.css';
if (is_editor_stylesheet($stylesheet_url)) {
echo 'The stylesheet is registered as an editor stylesheet.';
} else {
echo 'The stylesheet is not registered as an editor stylesheet.';
}
Add registered editor stylesheets to the frontend
This example enqueues all registered editor stylesheets on the frontend.
function enqueue_editor_stylesheets() {
$stylesheets = get_editor_stylesheets();
foreach ($stylesheets as $index => $stylesheet) {
wp_enqueue_style('editor-stylesheet-' . $index, $stylesheet);
}
}
add_action('wp_enqueue_scripts', 'enqueue_editor_stylesheets');
Count registered editor stylesheets
This example counts the number of registered editor stylesheets and displays the result.
$stylesheets = get_editor_stylesheets(); $count = count($stylesheets); echo 'There are ' . $count . ' registered editor stylesheets.';