4

I am using CKEditor to let people describe their organization with all the styles and fonts. So when it saves in the database its like < gets saved as &gt and rest all you know for the html tags. When I populate this page for public view I convert the &gt and &lt to html tags so no issue in displaying too. But the thing noticed recently is when I search the same profile in google I can see <strong> <p> such kind of tags their. Searched Google and Stack Overflow to solve the same but didn't help. Is their any feasible solution?

Sample example of how content from CKEditor stores in table is &lt;p&gt; Privacy Policy&lt;/p&gt; is this. I convert this on web page at load time to html tags so that people see the style and fonts what they wanted. But the Google search summary shows html tags(unwanted). The link for sample view of problem

  • 1
    Are you using ckeditor on your own site or as part of a pre-built CMS? I'm not sure how ckeditor works on the back end but you shouldn't be saving the HTML entities (eg. &gt;) in the database - this is what's ultimately causing the problems and making it harder to work with. Only when you display this content in an HTML context (ie. "populate this page for public view") should you be converting to HTML entities. – MrWhite Apr 20 '15 at 8:07
  • I am using OpenCart which is a MVC for ecommerce kind of sites. – Preeti Maurya Apr 20 '15 at 8:08
  • but i do use a jquery script on page load for replacing all the &gt and &lt before showing it to public. So when someone clicks on the google link the page shows fine.But I will do try and tell @w3d how your suggestion helped. Thanks! – Preeti Maurya Apr 20 '15 at 8:11
  • 3
    That's the thing, you should never (or at least very rarely) have to manually convert HTML entities back into the real characters - especially not with JavaScript (jQuery). And that's the problem here... you have large code blocks that are encoded with HTML entities (so they are essentially just plain text) and this what Google has picked up in the search results - when this is displayed as-is on the webpage (ie. in the search results) the HTML entities are converted back to the real characters for display, which is what you are seeing. – MrWhite Apr 20 '15 at 8:23
  • Actually, looking at the content (which consists of large blocks of HTML entity encoded text - which should simply be raw HTML) it doesn't look like you should be encoding/decoding anything. The text (HTML) should be stored as-is in the database and simply output directly to the page. (Although if this is user submitted content - although it doesn't look like it, since this is your actual page content (maybe entered by an Admin?) - then this would have other security implications.) – MrWhite Apr 20 '15 at 8:37
1

If you don't use <meta name="description"> you need to add this to your html page <head></head>.

I use two PHP function for my content description before adding content to the
<meta name="description"> I use htmlspecialchars_decode()for skipping html characters, for more information about this function click here.

Use strip_tags() for skipping html tags, for more information about this function click here

In the end result in this case is

$noramlText = htmlspecialchars_decode(strip_tags($htmlText), ENT_COMPAT);

<meta name="description" content="<?php echo $normalText; ?>">

I'm sorry for bad English

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.