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 ...
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 ...
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 ...
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 $...
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 ...
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 ...
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,...
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 (...
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() {
...
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( '...
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 ...
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['...
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-...
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-...
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 ...
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'] = ...
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.
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 ...
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( '...
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 ...
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
...
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' );
$...
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 ...
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' );
}
...
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 ( '...
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 ...
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 ...
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 '', ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
editor × 564tinymce × 87
posts × 49
plugins × 43
block-editor × 42
visual-editor × 38
admin × 29
wysiwyg × 28
customization × 27
images × 26
user-roles × 26
wp-editor × 26
css × 24
pages × 23
functions × 22
custom-post-types × 21
javascript × 21
html × 21
php × 19
metabox × 19
post-editor × 18
themes × 17
wp-admin × 16
custom-field × 14
plugin-development × 13