fix(widgets): render article sidebar by viewport CSS

This commit is contained in:
2026-08-14 12:39:37 +08:00
parent 224797cc39
commit f8dd319524
3 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ if (!function_exists('aksrt_single_render_aside')) :
* @param array<string,mixed> $ctx Single context.
*/
function aksrt_single_render_aside(array $ctx): void {
if (empty($ctx['show_aside']) || wp_is_mobile()) {
if (empty($ctx['show_aside'])) {
return;
}
+4 -2
View File
@@ -106,8 +106,10 @@ if (!function_exists('aksrt_single_build_context')) :
$has_article_widgets = is_active_sidebar('all_sidebar_top')
|| is_active_sidebar('sidebar-article')
|| is_active_sidebar('all_sidebar_bottom');
$show_aside = !wp_is_mobile()
&& get_post_type($post_id) === 'post'
// Do not use wp_is_mobile() as a layout gate. It is User-Agent based and
// can disagree with the actual viewport (for example, desktop-mode mobile
// browsers). The responsive stylesheet owns narrow-screen hiding.
$show_aside = get_post_type($post_id) === 'post'
&& $layout !== 'no_sidebar'
&& $has_article_widgets;
+4 -1
View File
@@ -212,7 +212,10 @@ function aksrt_get_site_layout(): int {
$has_article_widgets = is_active_sidebar('all_sidebar_top')
|| is_active_sidebar('sidebar-article')
|| is_active_sidebar('all_sidebar_bottom');
if (get_post_type($post_id) !== 'post' || wp_is_mobile() || $layout === 'no_sidebar' || !$has_article_widgets) {
// Keep the sidebar in the document whenever it is configured. CSS handles
// narrow viewports; wp_is_mobile() is User-Agent based and can otherwise
// suppress widgets on a desktop-sized page.
if (get_post_type($post_id) !== 'post' || $layout === 'no_sidebar' || !$has_article_widgets) {
return 1;
}