This can be done. @TomJNowell does point out the potential for a problem with this solution in the comments to the question but I cannot replicate that problem in any test.
In this example I locked on to the template slug. Therefore for this to work instead of using is_front_page() or similar, create a template called homepage and use it only for the homepage. Then do the same for any other pages you want to have a custom stylesheet.
add_action('enqueue_block_assets', function () {
global $post;
$template = get_page_template_slug($post->ID);
wp_enqueue_style(
$template . '-template-styles',
get_template_directory_uri() . "https://wordpress.stackexchange.com/" . $template . '.css',
);
});
Related Posts:
- How to conditionally enqueue a stylesheet only for a certain page(s)?
- Enqueue styles in new site editor in WordPress 5.9
- Remove Open Sans from Twenty Twelve theme
- Enqueue Google Web Fonts Without Messing Up Symbols In URL
- How to enqueue style before style.css
- Are there Gutenberg container blocks?
- What is the correct way to enqueue multiple CSS files?
- show classes as dropdown in guttenberg`s additional css classes input box
- Remove wp_add_inline_style
- Style new block-editor alignfull class without scrollbars or overflow
- Why isn’t my theme processing SASS?
- What CSS rules are introduced to core blocks through wp-block-styles?
- How to combine multiple CSS files and concatenate JavaScripts if WordPress recommends enqueuing them?
- Adding style sheet to specific page
- Load custom css after bootstrap
- Enqueue style for Password Reset page
- If I dequeue Gutenberg Stylesheet will that have any effect on WordPress 5.0.1?
- Is it possible to change the path of a css file that is registered through wp_enqueue_style()?
- Remove WordPress/Gutenberg button styles for ACF blocks
- Relative path instead of absolute for wp_enqueue_script
- get_stylesheet_uri returns wrong path
- Relative path in wp_register_style not working
- How to override Gutenberg admin CSS
- How the Css File is Linked without calling it in header.php?
- Loading different stylesheet on WordPress pages?
- Use wp_add_inline_style to add code to before wp_head?
- why enqueued styles in header.php shows in footer?
- Different css rules for TinyMCE and Gutenberg while using add_editor_style()
- How to insert html/css/javascript code to wordpress plugin
- Different ways to load child theme css
- How to enqueue a random css style?
- Can you edit WP gutenberg block css without a plugin?
- How to override Bootstrap css with my child theme css in wordpress?
- How to stop Gutenberg from outputting inline CSS for specific blocks?
- How to check if a WordPress core block is active in sidebar
- How to organize priority of plugins CSS files?
- How do I make header.php use different css for different pages?
- Child theme stylesheet not always overriding “index”
- Child Theme CSS not showing at all
- Faster fonts on mobile
- Display Something in the Header After All Styles are Loaded
- Using PHP Increment and Conditional Statement to Alternate Loop Background
- My CSS suddenly doesn’t load anymore [closed]
- How can I force Dynamic CSS via ACF values to update on page load?
- functions.php – inject inline css from file
- Append style tag in head while shortcode runs
- How can I move my custom css to the very bottom of the head section?
- Add Custom Alignment Option to WordPress Blocks/Gutenberg
- Simple way to add custom class and ids to individual Gutenberg blocks
- enqueing Javascript and CSS
- Including CSS files in HEAD based on page content
- How would one set or override a Fallback font for characters in second language?
- First element/selector of enqueued CSS file breaks
- The Global Styles missing
- ACF Gut block broke wordpress default style?
- Scroll code block instead of wrapping text
- Default paragraph block styles just for pages NOT for posts?
- Custom CSS in Widget editor (Gutenberg) gets stripped out
- Custom Gutenberg color classes naming convention
- Loading a stylesheet conditionally & verifying CSS
- Dequeue styles with query doesn’t work
- Stop custom Gutenberg styles taking over other admin bits?
- Save custom option in CSS file
- How to enqueue stylesheets in child-theme functions.php?
- Why can’t blocks be hidden with jQuery?
- Add inline CSS to login page with wp_add_inline_style
- Gutenberg CSS Issue
- What is the cleanest way to shrink Gutenberg Blocks to container width?
- Gutenberg Editor: display error with a combination of transform and background-attachment:fixed
- Bootstrap Integtration
- Default Gutenberg CSS on frontend
- Font size decreases when child theme is created from parent theme?
- Controling css order
- Why are my parent styles loading after my child styles?
- How to make CSS load live based on options clicked in the theme customizer?
- Replacing parent theme’s IE-specific CSS
- Use of CSS classes in editor-blocks.css file
- Browser stacks different versions of style.css
- Bootstrap 4 Optimization
- How do I make my block-editor styles match my front-end styles?
- Dequeue classic-themes.min.css
- How can I add a section with a different background color?
- Enqueue MCE Editor CSS in admin page
- plugin not loading my css and js
- Narrow paragraph block aligned to left of “wrapper”
- adding additional css classes have no effect within block editor
- Custom theme – Bootstrap CSS not loading via wp_enqueue_style or otherwise
- How do I change search input padding for blockbase child theme?
- Insert a group block inside a list item
- How enqueue CSS out of theme folder?
- Full Site Editing Non-editble global styles?
- Block content rendered with inline CSS. How do I reuse it in a headless setup?
- How to add arbitrary custom CSS to a WordPress Block Theme using Site Editor?
- Gutenberg: where to find style settings
- Custom block style not working in the editor
- Customize margin between paragraphs using the Gutenberg Style editor
- Style priority in theme.json
- How to add a class to a core block in both admin editor and frontend?
- How to force Gutenberg to follow all custom CSS styling in preview?
- Separate typography controls for titles and meta in a custom block?