- This topic has 17 replies, 3 voices, and was last updated 4 years ago by
Fernando.
-
AuthorPosts
-
March 2, 2022 at 3:39 pm #2140070
Math
Hi,
Is there a way to limit the height of a block within the block editor?
For example, I have a “pre” block with code in it and it’s taking up a significant amount of space (see link).
Is there a way to set a limit so the max-height is 100px, then you would have to scroll to see the rest?
Thank you.
March 2, 2022 at 3:43 pm #2140078Leo
StaffCustomer SupportHi there,
I can’t recall a solution off the top of my head.
This isn’t something GP (any themes) can control though so I’d recommend checking with WP’s support team.
Thanks for your understanding 🙂
March 2, 2022 at 3:44 pm #2140080Math
I looked around and didn’t find a suitable option. Thanks though.
March 2, 2022 at 3:46 pm #2140083Leo
StaffCustomer SupportWP’s support team would be able to point you in the right direction if there is indeed a way.
March 2, 2022 at 6:19 pm #2140179Math
I may have found a workaround by introducing an editor-style.css to manage the appearance of the block editor.
Added the following to
functions.phpadd_action( 'enqueue_block_editor_assets', function() { wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } );Then added the following to the
editor-style.css.editor-styles-wrapper .block-editor-block-list__layout pre { max-height: 100px; }It’s a bandaid fix but seems to do the job for now.
Is there any way to target the style to a specific page? I tried including the page id, but it didn’t work.
March 2, 2022 at 6:38 pm #2140185Fernando Customer Support
Hi Math,
You can add a conditional rule in your current PHP code to target a specific page:
add_action( 'enqueue_block_editor_assets', function() { if(is_page(123)){ wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } } );Kindly replace
123with the ID of the specific page.Hope this helps! 🙂
March 2, 2022 at 6:44 pm #2140186Math
Hi Fernando,
That’s great. Just out of curiosity, is there a way to use Elements to target specific pages? If I have 20 pages, I’m assuming I would have to adjust the code accordingly.
Thank you.
March 2, 2022 at 6:49 pm #2140190Leo
StaffCustomer SupportFernando’s code should be added as a function using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/You can take a look at the conditional tags here:
https://codex.wordpress.org/Conditional_Tags#A_PAGE_PageMarch 2, 2022 at 7:01 pm #2140199Math
Hi Leo,
I added the code above targetting the specific page and it doesn’t appear to be working on the page (I changed the page ID). The code without targeting the page seems to be working, but it’s on all pages.
add_action( 'enqueue_block_editor_assets', function() { if(is_page(13508)){ wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } } );Any idea why?
Thank you.
March 2, 2022 at 8:32 pm #2140245Fernando Customer Support
That should work for pages. Is the page you’re modifying a post? Kindly change it to
is_single(13508)if so. Please check for any syntax error. Kindly check if the ID is indeed13508as well. 🙂Alternatively, if that doesn’t work, you may use a plugin to implement custom CSS for specific pages. See: https://wordpress.org/plugins/simple-css/
Hope this helps. 🙂
March 3, 2022 at 6:02 am #2140702Math
Hi Fernando,
It is in fact a page and ID is correct (13508). Unfortunately, changing it to
is_single(13508)also didn’t work.I have a temporary solution where it applies to everything and I’ll work with it for the time being.
Thanks for your help.
March 3, 2022 at 5:40 pm #2141558Fernando Customer Support
I see. If you still wish to try, you may replace
enqueue_block_editor_assetswithwp_enqueue_scriptsinstead. I tested this on my test website and it works. I believe the likely reason whyenqueue_block_editor_assetisn’t working is because it’s a hook being called much earlier wherein the page ID hasn’t been initiated yet.add_action( 'wp_enqueue_scripts', function() { if(is_page(123)){ wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } } );Hope this helps! Kindly let us know how it goes. 🙂
March 6, 2022 at 2:08 pm #2144660Math
Hi Fernando,
I appreciate you going out of the way to look into this issue, but still not working. I must be doing something wrong on my end. I’ll create another ticket if I need to target a specific page in the future.
Thank you.
March 6, 2022 at 5:45 pm #2144757Fernando Customer Support
You’re welcome! If you like, you can also try hooking the action hook to the header to make sure the page has initiated first. Here is a sample code:
add_action( 'get_header', function() { if(is_page(13508)){ add_action( 'wp_enqueue_scripts', function() { wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } ); } } );Tested this as well and it’s working on my test website.
Hope this helps and hope you figure out why it isn’t working. Feel free to reach out anytime if you’ll need assistance with anything else! 🙂
March 6, 2022 at 6:15 pm #2144781Math
Hi Fernando,
Once again, thanks for the extra effort but this code didn’t work either. I looked around and tried a number of options and the following seems to have worked.
Would you happen to know if I need to include multiple pages, how I would go about it?
add_action( 'enqueue_block_editor_assets', function() { if(get_the_ID() == 13508){ wp_enqueue_style( 'my-block-editor-styles', get_stylesheet_directory_uri() . "/editor-style.css", false,'1.0', 'all' ); } } );Thank you.
-
AuthorPosts
- You must be logged in to reply to this topic.