Hot answers tagged

70 votes
Accepted

Enable Gutenberg on custom post type

For Gutenberg to work in a Custom Post Type you need to enable both the editor in supports (which you already have) and show_in_rest. So add 'show_in_rest' => true, to your post registration ...
Alvaro's user avatar
  • 2,563
24 votes

how to know if admin is in edit page or post

Better way: global variable $pagenow global $pagenow; if (( $pagenow == 'post.php' ) || (get_post_type() == 'post')) { // editing a page } if ($pagenow == 'profile.php') { // editing ...
T.Todua's user avatar
  • 5,689
15 votes
Accepted

Gutenberg editor add a custom category as wrapper for custom blocks

Digging myself deeper in documentation, I got the following result. There is a way to group your custom blocks around a given category in Gutenberg, and therefore we have the method ...
fefe's user avatar
  • 844
10 votes

Disable HTML (Text) Tab in Post Editor

I was hunting for a way to do this, and no-one seems to mention the wp_editor_settings filter. This worked for me: function my_editor_settings($settings) { $settings['quicktags'] = false; return $...
Stef Williams's user avatar
10 votes

Keyboard shortcut for updating a page or post?

I was curious about this and checked the Codex on keyboard shortcuts, but didn't find it mentioned there. I searched and found out that this seems to be already solved, e.g. here and here. I haven't ...
birgire's user avatar
  • 66.6k
9 votes

Forcing reload of editor-style.css

I couldn't get toscho's answer to work for the current version of WordPress (4.7.2), and that seems to be because the TinyMCE init array has a cache_suffix set to 'wp-mce-' . $tinymce_version. So ...
icecold_3000's user avatar
9 votes
Accepted

Force TinyMCE editor's "Toolbar Toggle" to be automatically chosen & expanded

Add below function in your activated theme's functions.php file. function changeMceDefaults($in) { // customize the buttons $in['theme_advanced_buttons1'] = 'bold,italic,underline,bullist,...
Milap's user avatar
  • 210
9 votes
Accepted

How to use wpLink without editor?

There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is not there (...
Sumit's user avatar
  • 4,764
9 votes

Enable Gutenberg on custom post type

Start by registering a Gutenberg WordPress custom type. The process is fairly easy and involves adding the following the code snippet. /*Register WordPress Gutenberg CPT */ function cw_post_type() { ...
Owais Alam's user avatar
8 votes
Accepted

How can I allow a custom taxonomy for certain roles?

When registering your taxonomy you can pass an argument called capabilities. Simply passing capabiities that only admins and editors have. $args = array( 'capabilities' => array( '...
mrbobbybryant's user avatar
8 votes
Accepted

How to create WP Editor using javascript

Thanks to Jacob Peattie's comment I can answer this using JS only. Actually we did something similar, but prior 4.8 and it wasn't this easy, so we did use wp_editor() in the end. But now, you can do ...
kero's user avatar
  • 6,180
8 votes
Accepted

Disable text tab on WordPress text-editor

For disabling the text tab for all users except administrators, you can add the following: function my_editor_settings($settings) { if ( ! current_user_can('administrator') ) { $settings['...
L.Milo's user avatar
  • 183
7 votes

how to know if admin is in edit page or post

Use 'get_current_screen', just make sure beforehand, it exists. As codex says "This function is defined on most admin pages, but not all." This btw also filters out normal (reader-facing) views (re-...
Frank N's user avatar
  • 455
7 votes
Accepted

How to display warning on post editor when trying to add new term to custom taxonomy?

Whilst this doesn't show a warning as you are asking for, you could always hide the "add new" link using the admin_head action: function yourprefix_admin_head() { echo '<style> #language-...
Alexander Holsgrove's user avatar
7 votes

How to create WP Editor using javascript

WP 5.3.2 Currently building a plugin with Ajax page loading, needed to get data from multiple WP editors that are dynamicly loaded. NOTE: Below example is for the wp-admin area, if you want this ...
Bjorn's user avatar
  • 535
6 votes

Extra TinyMCE editor strips <p> and <br> tags?

This seems to have changed a little in subsequent versions of Wordpress. You can now disable this functionality thusly: add_filter('tiny_mce_before_init', function($init) { $init['wpautop'] = ...
Nathan Crause's user avatar
6 votes

Wordpress crop tool greyed out

For me, the button became available once I clicked and dragged the mouse cursor over part of the image to select an area to crop.
Highly Irregular's user avatar
6 votes

Admin: very slow edit page caused by core meta query

If you browse through the source code of the function you'll find this: $keys = apply_filters( 'postmeta_form_keys', null, $post ); if ( null === $keys ) { ... } Using the ...
Dan K's user avatar
  • 61
6 votes
Accepted

WordPress 4.6 link edit dialog is too rudimentary

To disable the inline link tool and revert it back to a pop-up screen instead, do the following: In your child theme directory, add the following to your function.php: add_filter( '...
Ethan O'Sullivan's user avatar
5 votes

Wordpress crop tool greyed out

The crop tool and edit-image interface is not as intuitive as it could be. For anyone looking for why the crop tool is deactivated and the save button is greyed-out, here are the steps for getting ...
Mike Kormendy's user avatar
5 votes
Accepted

Allow editors access to added plugins

Please add the following code. function activate_plugin_name() { $role = get_role( 'editor' ); $role->add_cap( 'manage_options' ); // capability } // Register our activation hook ...
Liz Eipe C's user avatar
4 votes

How to include own css on wordpress tinymce editor?

Nothing I found worked. Took me half a day on Google, but finally stumbled upon this script that works: function kwh_add_editor_style( $mceInit ) { $custom_css = get_theme_mod( 'custom_css' ); $...
AA-T's user avatar
  • 51
4 votes

How can I allow a custom taxonomy for certain roles?

I never played with roles before so this was a fun learning experience. I'm leaving this because I've spent a lot of time researching this area and this might help the next person. I know my ...
user9447's user avatar
  • 1,762
4 votes
Accepted

How to enable the theme editor cap for an editor role?

The edit_themes capability is what allows access to Appearance > Theme Editor: function wpse243341_modify_editor_role() { $role = get_role( 'editor' ); $role->add_cap( 'edit_themes' ); } ...
Dave Romsey's user avatar
  • 17.6k
4 votes

wp.media edit attachment screen

Long answer: Peeking into wp-includes/js/media-models.js, I see this: if ( 'select' === attributes.frame && MediaFrame.Select ) { frame = new MediaFrame.Select( attributes ); } else if ( '...
user63350's user avatar
  • 171
4 votes

Why wordpress word count differs from Microsoft word and sites like wordcounter.net

WordPress removes HTML entities, convert connectors (-- or em-dash) to spaces, removes unwated characters (General Punctuation, Superscripts and Subscripts, Currency Symbols, Combining Diacritical ...
KAGG Design's user avatar
  • 1,832
4 votes

Gutenberg block editor - list of form components for custom blocks

There are two main packages that provide components which can be used inside the blocks API or the plugins API (to create your own blocks or plugins). The components found in the wp.components ...
Alvaro's user avatar
  • 2,563
4 votes
Accepted

How to get value of selected page template in Gutenberg editor?

I slightly modified SkyShab's code, because it fired template change event on page load and it didn't fire when template was changed to default (since getEditedPostAttribute( 'template' ) is then '', ...
Lovor's user avatar
  • 861
3 votes

Admin: very slow edit page caused by core meta query

had that issue still in the year 2022 because i have over 10.000 posts and each has 30 meta keys/values. so there is an easy and performant workaround if you insert that piece of code in your ...
Nic Bug's user avatar
  • 131

Only top scored, non community-wiki answers of a minimum length are eligible