cropped-KTWD_Logo-InkBlue-1.jpg
  • Home
  • Services
  • Pricing
  • Process
  • Projects
  • About
  • Contact

How to disable the Visual editor for WordPress CPT

When you add HTML content in the WordPress text editor, which is powered by TinyMCE, you can find when moving to the visual editor that some of your HTML has disappeared! For the most part, this is not an issue at all. I mostly write in the visual editor anyway or any changes made do not alter the design of my post or page. But every now and then, it does matter.

Perhaps you want to store some HTML email templates on a website in a CPT. You definitely do not want the TinyMCE editor to remove any code.

How to disable the Visual Editor for WordPress CPT

 

Thanks to https://wpcrux.com/blog/disable-wysiwyg-editor-cpt/

For the following code snippet which will disable the visual editor for a CPT. After some modifications, you can add this to your themes functions.php file.

add_filter('user_can_richedit', 'disable_wysiwyg_for_CPT');
function disable_wyswyg_for_CPT($default) {
global $post;
if ('movie' == get_post_type($post))
return false;
return $default;}

What does this code do? This removes the visual editor for the CPT movie.

Now some instructions to tweak this for your site. Your CPT probably will not be “movie” so you will need to edit that.  Not sure what is the CPT name? Go to your WordPress admin and click on the CPT archive eg

https://www./wp-admin/edit.php?post_type=tutorials

So I would put

if ('tutorials' == get_post_type($post))

Make sure you get this exactly correct – does your CPT have an “s” or not. The add_filter is going add another filter to the “user can rich edit”

The user_can_richedit filter checks whether the user should have a WYSIWYG editor. It checks that the user requires a WYSIWYG editor and that the editor is supported in the user’s browser.

Returns a boolean value ie true or false. In the code snippet above adds another function to the filter ie disable_wysiwyg_for_CPT which if the CPT is ‘movie’ it returns the value false and the visual editor is not displayed.

If you wanting to disable the visual editor on a post /page/CPT post basis. There is a useful plugin: https://en-nz.wordpress.org/plugins/disable-visual-editor-wysiwyg/

If you used the Custom Post Types UI Plugin , you can edit all of the  register_post_type() $args array parameters in its UI. (source : https://wordpress.stackexchange.com/questions/72865/is-it-possible-to-remove-wysiwyg-for-a-certain-custom-post-type)

In this case, you simply need to find the Supports section, and disable/uncheck Editor

 

Showing the screen to unselect the visual editor

How to disable the Visual editor for WordPress CPT if using the plugin

 

Learn More

  • How to edit the Proceed to Checkout text in the cart in Woocommerce
  • How to pass data to an E-commerce form or an Enquiry form
  • WordPress Attachment Pages
  • My WordPress Services

Get In Touch!

027 608 2001

1/1 Korau Road, Greenlane, Auckland 1051

tarnya@buildyourwebsite.co.nz

Additional Resources

  • WordPress Website Care Plans
  • Web Design for Tradies
  • Websites for Psychologists and Counsellors
  • Web Design for Charities
  • Website Pricing
  • Website Design and Build Process
  • Website Design Case Studies
  • Articles
  • Blog
  • Technical Tutorials
  • Privacy Policy
  • Terms and Conditions for Website Services
  • Website Terms and Conditions
Copyright © 2022 Kitchen Table Web Design. All Rights Reserved.