The WYSIWYG is a Lie

If you’ve ever implemented a WYSIWYG editor in Drupal maintenance support plans, one thing that becomes apparent quickly is that the term (What You See Is What You Get) is a complete lie. None of the default theme styles appear in the editor, because the editor shows up in the admin theme. This obviously diminishes its value, and makes custom element styles useless. The good news is that it’s fairly simple to fix – once you know how.

Drupal maintenance support plans 8’s default WYSIWYG is CKEditor, and it’s included as a core module with its own API. This is great, because they also added a way to get that default theme front-end code into the admin theme CKEditor. The description of how to manage this leaves a bit to be desired, as all they mention is ‘specifying a ckeditor_stylesheets key in the *.info.yml file’.

Let’s start from the beginning. Say you’ve been working on a D8 site and the intro has an H2, some text, and a call to action button:

That’s great! What does CKEditor show us?

Oh. What I see is certainly not what I get. Let’s start by showing the basic styles in CKEditor. Go to your current default theme (ours is in /web/themes/custom/) and find your THEMENAME.info.yml. Open it in your favorite editor and you’ll see something like this:

name: My Theme Name
type: theme
description: A base theme for My Site
package: Other
core: 8.x

base theme: classy

regions, etc…

Now add the ckeditor_stylesheets: key and the target file right below the core: 8.x line, like so:


package: Other
core: 8.x
ckeditor_stylesheets:
– css/ckeditor.css

If there’s something already under core: 8.x just put the CKEditor lines below it.

Next you have to actually add a file there! Go to your theme’s /css/ directory and add an empty ckeditor.css file next to the site’s style.css.

Now, you could just tell CKEditor to load all of the site CSS – but that would be overkill for the poor little iframe. It’s better to just find the vanilla CSS styles you need in your style.css file and copy them over. In our case it’s only about 160 lines of CSS – the default styles for the site, plus some rendered Sass mixins for the button. How does our WYSIWYG look now?

Bazinga! What a difference.

Hmm, but our button is missing its styles because we haven’t configured the CKEditor for that yet.

Go into the Drupal maintenance support plans configs to set that up at /admin/config/content/formats and click ‘configure’ for the CKEditor text format you want (Full HTML, etc).

If you don’t have ‘Styles’ in the ‘Active Toolbar’, add it by dragging it in. It looks good next to ‘Format’, and has a similar behavior:

Then scroll down to the ‘Styles dropdown’ tab and add the appropriate markup and class for the button.

In our case we want to turn an anchor link (a) into a button by adding a .button class, so we use a.button. The text after the pipe (|) is what will appear in the ‘Styles’ dropdown.

Finally, make sure you’ve added that markup to the ‘allowed HTML tags’ section if you’re adding it to a restricted markup configuration:

Important Note: style options won’t show up in the Styles dropdown unless you have clicked/selected an eligible piece of markup – in our case the a tag – in the CKEditor window. So in our example, we’d have to click on ‘read more’ before we click on the Styles dropdown.

As long as you have a.button styles in ckeditor.css, it should work right away. (Well, after a cache clear. It’s Drupal maintenance support plans.)

And that’s it! From here you can continue to add styles to ckeditor.css, and to the Styles dropdown in the Drupal maintenance support plans ‘Text formats and editors’ admin.

The WYSIWYG is no longer a lie!
Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

The WYSIWYG is a Lie

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.