Skip to content

Commit 506847f

Browse files
authored
Merge pull request #4299 from ampproject/4297-load-block-styles-in-reader-mode
Load block styles via amp_post_template_head action
2 parents cd1e2bf + 7400d2b commit 506847f

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

includes/amp-post-template-functions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function amp_post_template_init_hooks() {
1515
add_action( 'amp_post_template_head', 'amp_print_schemaorg_metadata' );
1616
add_action( 'amp_post_template_head', 'amp_add_generator_metadata' );
1717
add_action( 'amp_post_template_head', 'wp_generator' );
18+
add_action( 'amp_post_template_head', 'amp_post_template_add_block_styles' );
1819
add_action( 'amp_post_template_css', 'amp_post_template_add_styles', 99 );
1920
add_action( 'amp_post_template_data', 'amp_post_template_add_analytics_script' );
2021
add_action( 'amp_post_template_footer', 'amp_post_template_add_analytics_data' );
@@ -54,6 +55,19 @@ function amp_post_template_add_fonts( $amp_template ) {
5455
}
5556
}
5657

58+
/**
59+
* Add block styles for core blocks and third-party blocks.
60+
*
61+
* @since 1.5.0
62+
*/
63+
function amp_post_template_add_block_styles() {
64+
add_theme_support( 'wp-block-styles' );
65+
if ( function_exists( 'wp_common_block_scripts_and_styles' ) ) {
66+
wp_common_block_scripts_and_styles();
67+
}
68+
wp_styles()->do_items();
69+
}
70+
5771
/**
5872
* Print styles.
5973
*

templates/style.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@
2828
$link_color = $this->get_customizer_setting( 'link_color' );
2929
$header_background_color = $this->get_customizer_setting( 'header_background_color' );
3030
$header_color = $this->get_customizer_setting( 'header_color' );
31+
32+
$alignwide_max = $content_max_width > 0 ? $content_max_width * 2 : 1920
3133
?>
3234
/* Generic WP styling */
3335

36+
.alignnone,
37+
.aligncenter,
38+
.alignleft,
39+
.alignright,
40+
.alignwide {
41+
margin-top: 1em;
42+
margin-right: auto;
43+
margin-bottom: 1em;
44+
margin-left: auto;
45+
}
46+
3447
.alignright {
3548
float: right;
3649
}
@@ -46,6 +59,35 @@
4659
margin-right: auto;
4760
}
4861

62+
.alignwide {
63+
width: 100%;
64+
}
65+
66+
@media (min-width: calc(840px - 48px)) {
67+
.alignwide {
68+
width: calc(100vw - 48px);
69+
max-width: calc(100vw - 48px);
70+
margin-left: calc(50% - 50vw + 24px);
71+
margin-right: calc(50% - 50vw + 24px);
72+
}
73+
}
74+
75+
@media (min-width: calc(<?php echo sprintf( '%dpx', $alignwide_max ); ?>)) {
76+
.alignwide {
77+
width: calc(<?php echo sprintf( '%dpx', $alignwide_max ); ?> - 48px);
78+
max-width: calc(<?php echo sprintf( '%dpx', $alignwide_max ); ?> - 48px);
79+
margin-left: calc(calc(50% - <?php echo sprintf( '%dpx', $alignwide_max ); ?> / 2) + 24px);
80+
margin-right: calc(calc(50% - <?php echo sprintf( '%dpx', $alignwide_max ); ?> / 2) + 24px);
81+
}
82+
}
83+
84+
.alignfull {
85+
width: 100vw;
86+
max-width: 100vw;
87+
margin-left: calc(50% - 50vw);
88+
margin-right: calc(50% - 50vw);
89+
}
90+
4991
.amp-wp-enforced-sizes {
5092
/** Our sizes fallback is 100vw, and we have a padding on the container; the max-width here prevents the element from overflowing. **/
5193
max-width: 100%;
@@ -268,11 +310,13 @@
268310
margin: 0 auto;
269311
}
270312

271-
.amp-wp-article-content amp-img.alignright {
313+
.amp-wp-article-content amp-img.alignright,
314+
.amp-wp-article-content .wp-block-cover.alignright {
272315
margin: 0 0 1em 16px;
273316
}
274317

275-
.amp-wp-article-content amp-img.alignleft {
318+
.amp-wp-article-content amp-img.alignleft,
319+
.amp-wp-article-content .wp-block-cover.alignleft {
276320
margin: 0 16px 1em 0;
277321
}
278322

0 commit comments

Comments
 (0)