Disable WYSIWYG rich text editor only on post excerpt

by Jason   Last Updated April 16, 2018 07:08 AM

I am pulling info from the excerpt of a custom post type into a 3rd party application. I need to be able to add line breaks and for them to be saved in the database. If my user switches to "visual" from "text" and saves the post, the
tags are stripped out.

My solution was to disable the use of the rich text editor for my custom post type. Solution was from user @biziclop here; Is it possible to remove WYSIWYG for a certain Custom Post Type?

add_filter('user_can_richedit', 'disable_wyswyg_for_custom_post_type');
function disable_wyswyg_for_custom_post_type( $default ){
  if( get_post_type() === 'custom-post-type') return false;
  return $default;

I need to leave the WYSIWYG tools for the main post content. Reading the codex, there are no parameters for the user_can_richedit function: https://codex.wordpress.org/Function_Reference/user_can_richedit

Is there a way to modify my filter to only target the excerpt?

Thank you in advance!

Tags : excerpt wysiwyg

Answers 1

Excerpts can be automatically generated in which case you have some control over them or manually generated in which case there is very little control available, and the wordpress way is that they may have any type of content. if you need something more restrictive you will need to create your own "meta box" for your specific needs, and probably design an API to retrieve it.

The other alternative is to not use an excerpt retrieved using the wordpress APIs but generate one by yourself from the content.

Mark Kaplun
Mark Kaplun
April 16, 2018 06:30 AM

Related Questions

Certain number of posts with certain excerpt length

Updated April 30, 2016 08:03 AM

Custom wp_trim_words() function not trimming right

Updated March 21, 2016 08:03 AM

How to get excerpt of the recent posts

Updated December 28, 2016 08:03 AM