Hot answers tagged

67 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 ...
user avatar
  • 2,423
18 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 ...
user avatar
  • 5,261
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 ...
user avatar
  • 822
12 votes
Accepted

Is it OK to remove theme credits from footer?

On a free and publicly available theme, yes, you can! If you built the theme yourself, yes, you can! If the theme is under a GPL license or completely public domain, yes, you can! But If you're a ...
user avatar
  • 51.7k
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 ...
user avatar
  • 63.8k
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 ...
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,...
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 (...
user avatar
  • 4,654
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() { ...
user avatar
8 votes

Allow user to "edit_others_posts" to save only, not publish

If I understand well, user having a special role in your site should: Be able to edit own posts in all statuses but 'publish' and not be able to publish them, just send for revision Be able to edit ...
user avatar
  • 44.6k
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( '...
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 ...
user avatar
  • 5,890
7 votes
Accepted

WordPress 3.9 - Trouble Editing TinyMCE 4.0

The strings was new, not more for your requirements. This is the new content of the hook. array ( 'selector' => '#content', 'resize' => 'vertical', 'menubar' => false, 'wpautop' =&...
user avatar
  • 16.6k
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-...
user avatar
7 votes
Accepted

How to add a class to the attachment images

You could do like this: function image_tag_class($class) { $class .= ' my-custom-class'; return $class; } add_filter('get_image_tag_class', 'image_tag_class' ); in case you wanna know more ...
user avatar
7 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 $...
user avatar
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-...
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.
user avatar
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'] = ...
user avatar
6 votes

WordPress 3.9 - Trouble Editing TinyMCE 4.0

One change is that: theme_advanced_buttons1 is going to be changed to: toolbar1 which allows you to update the buttons so my new function will look something like: function myformatTinyMCE( $in ) { ...
user avatar
  • 19.6k
6 votes

Open posts in editor in the 'Text' mode by default

Add the following line to your theme's functions.php: add_filter( 'wp_default_editor', create_function( '', 'return "html";' ) ); Use "html" to set the Text editor tab as default (as shown above), ...
user avatar
  • 2,230
6 votes

Disable HTML (Text) Tab in Post Editor

I was able to resolve both defaulting to the Visual editor and hiding the tabs with the following code. Dumped the following in plugin file: add_filter( 'wp_default_editor', array($this, '...
user avatar
  • 349
6 votes

Admin: very slow edit page caused by core meta query

If you want to test your custom SQL to see how it affects the loading time, you can try this query swapping: /** * Restrict the potential slow query in the meta_form() to the current post ID. * * ...
user avatar
  • 63.8k
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( '...
user avatar
6 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['...
user avatar
  • 153
5 votes

how to limit edit_form_after_title hook to page and post edit only?

Don't know if there was any change during the time that passed from the original question but as of 4.0 you get the post as a parameter to the hook and all that is needed to do is to check the post ...
user avatar
  • 22.6k
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 ...
user avatar
5 votes
Accepted

Wordpress tinymce prints empty P tag and break html format

You can disable the visual editor entirely in your profile settings. If you need to disable it on a per page basis, take a look at this answer. Using text mode may not solve the empty paragraph ...
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' ); $...
user avatar
  • 51

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