Content editor creating blank paragraphs in spaces and creating &nbsp in the_excerpt

Judging from your site’s content and the comments, you may try using the following CODE in your theme’s functions.php file. It’ll remove empty <p>&nbsp;</p> tags from post content: add_filter( ‘the_content’, ‘wpse_257854_remove_empty_p’, PHP_INT_MAX ); add_filter( ‘the_excerpt’, ‘wpse_257854_remove_empty_p’, PHP_INT_MAX ); function wpse_257854_remove_empty_p( $content ) { return str_ireplace( ‘<p>&nbsp;</p>’, ”, $content ); } However, after it removes the … Read more

Add option for editors through `register_setting`

To allow users with capabilities other than manage_options to save a setting you can use the option_page_capability_{$option_page} hook. Despite the name, {$option_page} is the option group, which is what you set for the first argument of register_setting() and settings_fields() on your options page. So if you registered a setting: register_setting( ‘wpse_310606_setting_group’, ‘wpse_310606_setting’ ); You can … Read more

add image map script to post

The post content is filtered by kses, but you can extend the list of allowed tags. A search in the plugin directory for kses shows some useful results. Try Extend KSES, it seems to be exactly what you need (I haven’t tested it): This plugin extends the HTML functionalify of the WordPress kses.php file, which … Read more

How to *disable* the post content editor

I think the best way is remove it and then print the content out of any textarea, but just as html: add_action(‘load-post.php’, ‘read_only_content’); function read_only_content() { if ( ! current_user_can(‘manage_options’) ) { // change the cap with the wanted one $scr = get_current_screen(); remove_post_type_support( $scr->post_type, ‘editor’ ); add_action(‘edit_form_after_editor’, ‘print_the_content’); } } function print_the_content( $post ) … Read more

How to apply editor filter to posts with a specific custom post type

You can determine the current post type using get_post_type() inside the callback function hooked to wp_default_editor: add_filter( ‘wp_default_editor’, ‘wpse242896_wp_default_editor’ ); function wpse242896_wp_default_editor( $editor ) { $post_type = get_post_type(); if ( ‘custom_post_type’ === $post_type ) { return ‘html’; } else if ( ‘other_post_type’ === $post_type ) { return ‘tinymce’; } return $editor; } Also, anonymous functions … Read more

Set default text for the editor in new posts

There is a filter named default_content. It does exactly what the name says. 🙂 Example: add_filter( ‘default_content’, ‘t5_preset_editor_content’, 10, 2 ); /** * Fills the default content for post type ‘post’ if it is not empty. * * @param string $content * @param object $post * @return string */ function t5_preset_editor_content( $content, $post ) { … Read more