I have a block template for a custom post type.
When the WP Core column block added support for different widths, I tried setting up the template like so (I changed the post type to "post" here in case anyone else plans to try it out):
<?php
add_action('init', 'wpse_register_post_template');
function wpse_register_post_template() {
$post_type_object = get_post_type_object('post');
$post_type_object->template = array(
array('core/columns', array(),
array(
array('core/column', array('width' => '33.33'), array(
array('core/paragraph', array()),
)),
array('core/column', array('width' => '66.66'), array(
array('core/paragraph', array()),
)),
)
)
);
}
?>
However, when I add a new post, this doesn't actually apply the column widths. They end up being two 50%-width columns, in the Editor and on the front end, even though the database shows the inner columns have the "width" attributes saved correctly.
It looks like this in the database -
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"33.33"} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>Left Col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"66.66"} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>Right Col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
In a post where I manually added the Columns block in the Editor, so I was able to choose the 33% / 66% widths from the UI, it looks like WP added inline styles to the divs:
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":33.33} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:paragraph -->
<p>Left col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":66.66} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:paragraph -->
<p>Right col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
Is there a way to update the CPT template so that the added blocks will have this same markup and thus have the different widths set on the columns right when I create a new CPT, rather than having to do it manually every time?
I have a block template for a custom post type.
When the WP Core column block added support for different widths, I tried setting up the template like so (I changed the post type to "post" here in case anyone else plans to try it out):
<?php
add_action('init', 'wpse_register_post_template');
function wpse_register_post_template() {
$post_type_object = get_post_type_object('post');
$post_type_object->template = array(
array('core/columns', array(),
array(
array('core/column', array('width' => '33.33'), array(
array('core/paragraph', array()),
)),
array('core/column', array('width' => '66.66'), array(
array('core/paragraph', array()),
)),
)
)
);
}
?>
However, when I add a new post, this doesn't actually apply the column widths. They end up being two 50%-width columns, in the Editor and on the front end, even though the database shows the inner columns have the "width" attributes saved correctly.
It looks like this in the database -
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"33.33"} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>Left Col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"66.66"} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>Right Col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
In a post where I manually added the Columns block in the Editor, so I was able to choose the 33% / 66% widths from the UI, it looks like WP added inline styles to the divs:
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":33.33} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:paragraph -->
<p>Left col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":66.66} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:paragraph -->
<p>Right col</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
Is there a way to update the CPT template so that the added blocks will have this same markup and thus have the different widths set on the columns right when I create a new CPT, rather than having to do it manually every time?
Share Improve this question asked Jan 27, 2020 at 15:19 WebElaineWebElaine 9,8041 gold badge17 silver badges28 bronze badges1 Answer
Reset to default 3 +100Change column width value from string to number, like this
array('core/column', array('width' => 33.33)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744791847a4593962.html
评论列表(0条)