Comments (4)
Hey @chriscoyier!
I think the best long-term solution for everyone would be to use Classic Editor over Gutenberg Ramp.
WordPress 5.0 introduced a filter use_block_editor_for_post
that allows to change whether or not Block Editor (Gutenberg) should be enabled for any given post.
I actually wrote a blog post about this 🙂 - https://pyronaur.com/how-to-dynamically-enable-gutenberg
The tldr; is - you can use that filter to enable Gutenberg for new posts. Here's a snippet from the post that will enable Gutenberg for new posts and posts that have blocks in them:
function maybe_enable_gutenberg( $can_edit, $post ) {
// -- For new posts
// Check for `/wp-admin/post-new.php`
$current = get_current_screen();
if ( 'post' === $current->base && 'add' === $current->action ) {
// For new posts,
// If using Classic Editor - return whatever the current default for the site is
return $can_edit;
}
// -- For existing posts
// Enable Gutenberg in posts with empty post content
if ( empty( $post->post_content ) ) {
return $can_edit;
}
// Determine whether Gutenberg should be
// enabled based on whether the post content has blocks
return has_blocks( $post );
}
// Classic Editor is using hook priority 100
add_filter( 'use_block_editor_for_post', 'maybe_enable_gutenberg', 200, 2 );
The snippet above should work in WordPress 5.0+ with and without Classic Editor and Gutenberg plugins. However - if the site should support Classic Editor for years to come - the Classic Editor plugin should probably be installed, as I don't know if/when Classic Editor will be removed from WordPress core.
With all that said, I think that to enable Gutenberg for post IDs above a certain number, it would be easier to just use WordPress Core hooks:
function over_9000( $can_edit, $post ) {
return ( $post->ID > 9000 );
}
add_filter( 'use_block_editor_for_post', 'over_9000', 10, 2 );
from gutenberg-ramp.
I have a monkey patch for this I could submit a PR for if there is any interest.
from gutenberg-ramp.
I wanted to be able to link to the code so here's a PR for it.
from gutenberg-ramp.
Oh wow - yeah essentially a one-liner there instead of an entire monkeypatched plugin seems like a way nicer approach, thanks.
from gutenberg-ramp.
Related Issues (20)
- In settings, improve checkbox UI for enabling custom post types HOT 6
- Cross linking an issue in regards to additional editing options HOT 1
- Suggested enhancements - to plugin or to documentation HOT 4
- generalize criteria for GB loading HOT 8
- Disable 'try Gutenberg' banner in wp 4.9.8, if using Ramp HOT 7
- Admin Alert when Gutenberg is off - dismissible forever HOT 1
- Autoloading ramp options HOT 3
- Does not support 'fallback' mode HOT 2
- allow opt-in to Gutenberg by post/page slug or tag HOT 2
- Bug: Gist embedding not displaying in editor HOT 1
- wpcom_vip_load_gutenberg doesn't allow meta boxes to be loaded HOT 3
- Disable Ramp when Gutenberg version requirements aren't met HOT 3
- All options in the UI should be greyed out in the cases where Ramp sets Gutenberg to always or never load
- Make Ramp + Classic Editor play nicer together HOT 2
- Make it clearer how to enable Gutenberg for all post types HOT 1
- Add some clarity to the documentation about Gutenberg requirement HOT 1
- Ability to modify admin screen access
- The UI isn't displaying at all. HOT 1
- Plugin always loads classic-editor when classic-editor plugin is installed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gutenberg-ramp.