1
votes

After a few days of searching and trying to solve, got nowhere.

CKEditor 4.7.0 is stripping the content between the <title></title> tags. I need CKEDitor to leave the title content alone no matter how / where the title tag is used.

I have tried:

  • allowedContent: true,
  • extraAllowedContent : 'title',
  • extraAllowedContent: 'title[*]',
  • config.allowedContent = true; (in config.js)
  • CKEDITOR.dtd.$removeEmpty['title'] = false; (in config.js)

No luck with above. Then tried suggestion here ckeditor deteles page <title></title> title which works, but I end up with:

<!DOCTYPE html>
<html>
<head>
    <title>OK Title</title>
</head>
<body>&nbsp;</body>
</html>
<p><br />
<title></title>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Web template presented with pure css."><meta name="keywords" content="css template"></p>
<link href="style.css" rel="stylesheet" />
<link href="red.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" /><!-- Header -->
<header class="w3-container w3-theme w3-padding" id="myHeader">
<div class="w3-center">
<h4>BEAUTIFUL RESPONSIVE WEB SITES</h4>

What I am doing is pasting into CKEditor an example CSS templates from https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_templates_black&stacked=h

I understand this is not the way standard HTML should be displayed (not to spec), but I need to prevent CKEditor from modifying the title tag no matter, just ignore it and let me use it wherever:) This is just a simple project for classroom where no one sees source of page and I need title tag to show in browser tab when I project page on whiteboard for students.

UPDATE: did discover if I save with the source in view, CKEditor does not modify the title tag. Works this way but not when in visual mode which like to have:)

1

1 Answers

2
votes

After what seemed like endless searches found some info on a drupal forum. Had so many links open lost track of exact site where obtained the info, sorry.

Solved the problem by adding the following to my config.js in CKEditor 4.7.0:

config.allowedContent = true;
config.protectedSource.push(/<title>[\s\S]*?<\/title>/gi); // allow content between <title></title>

Hope this will help someone else:)