WordPress块模板不允许 Bootstrap 控制响应

ghg1uchk  于 2023-09-28  发布在  Bootstrap
关注(0)|答案(1)|浏览(120)

我正在创建一个WordPress的主题。我想让WordPress的风格在其所有的内置块;然而,我在我的主题中创建的块,我想删除WordPress的样式,并允许 Bootstrap 来完全样式它们。我已经包括在我的主题引导,它正在加载.
我知道它是工作的,因为当我使用类text-primary时,它将字体格式化为蓝色。
我写了一个非常基本的jquery/JavaScript文件,如果我的块包含一个特定的类,它将搜索并删除该元素中数组中列出的WordPress类。这部分工作得很完美。我这样做的原因是因为WordPress在加载网站时会自动添加这些类,并且WordPress格式在响应性方面会覆盖bootstrap格式。当我的js文件删除类时,它删除了默认的wordpress响应。
在你说,这将打破每次WordPress更新和更改其类,我包括这个文件在父域,并可以更新它的所有网站实现我的自定义块主题和改变数组根据WordPress版本(我将添加后,一旦我得到这个完全工作)。
这就是问题出现的地方。我已经完全删除WordPress的样式自定义块主题;然而,当涉及到响应性时,bootstrap也不会对内容进行样式化。我希望有人能看看这个,并告诉我是什么阻止bootstrap控制如何显示内容,因为屏幕尺寸变大越来越小。它看起来好像它会完美地工作,如果我把代码直接上传到没有WordPress的网站,它会正确地样式它。
这些列被设置为从1列移动的设计,到更大屏幕上的2列设计,再到大屏幕上的4列设计。但它在Wordpress中不起作用。
我的JS文件:

var WPclasses  = [
  "wp-block-group",
  "is-layout-constrained",
  "wp-block-columns",
  "is-layout-flex",
  "wp-block-column",
  "is-layout-flow",
];


$(".WP-removeDefaultClasses").removeClass(WPclasses);

我的Wordpress内容块显示在代码编辑器中

<!-- wp:group {"className":"container WP-removeDefaultClasses","layout":{"type":"constrained"}} -->
<div class="wp-block-group container WP-removeDefaultClasses"><!-- wp:columns {"className":"row WP-removeDefaultClasses"} -->
<div class="wp-block-columns row WP-removeDefaultClasses"><!-- wp:column {"className":"col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"} -->
<div class="wp-block-column col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"><!-- wp:heading -->
<h2 class="wp-block-heading">Heading 1</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":10,"sizeSlug":"large","linkDestination":"none","className":"img-fluid"} -->
<figure class="wp-block-image size-large img-fluid"><img src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-1024x681.jpg" alt="" class="wp-image-10"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph {"className":"text-primary"} -->
<p class="text-primary">Paragraph 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"className":"col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"} -->
<div class="wp-block-column col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"><!-- wp:heading -->
<h2 class="wp-block-heading">Heading 1</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":9,"sizeSlug":"large","linkDestination":"none","className":"img-fluid"} -->
<figure class="wp-block-image size-large img-fluid"><img src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-1024x683.jpg" alt="" class="wp-image-9"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Paragraph 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"className":"col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"} -->
<div class="wp-block-column col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"><!-- wp:heading -->
<h2 class="wp-block-heading">Heading 1</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":8,"sizeSlug":"large","linkDestination":"none","className":"img-fluid"} -->
<figure class="wp-block-image size-large img-fluid"><img src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-1024x640.jpg" alt="" class="wp-image-8"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Paragraph 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"className":"col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"} -->
<div class="wp-block-column col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses"><!-- wp:heading -->
<h2 class="wp-block-heading">Heading 1</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":7,"sizeSlug":"large","linkDestination":"none","className":"img-fluid"} -->
<figure class="wp-block-image size-large img-fluid"><img src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-1024x576.jpg" alt="" class="wp-image-7"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Paragraph 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
<!-- /wp:group -->

在Wordpress源代码中输出的代码:

<div class="container WP-removeDefaultClasses">
<div class="row WP-removeDefaultClasses wp-container-5">
<div class="col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses">
<h2 class="wp-block-heading">Heading 1</h2>


<figure class="wp-block-image size-large img-fluid"><img decoding="async" width="1024" height="681" src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-1024x681.jpg" alt="" class="wp-image-10" srcset="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-1024x681.jpg 1024w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-300x199.jpg 300w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-768x511.jpg 768w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-1536x1021.jpg 1536w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-miguel-a-padrinan-255379-2048x1362.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>


<p class="text-primary">Paragraph 1</p>
</div>


<div class="col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses">
<h2 class="wp-block-heading">Heading 1</h2>


<figure class="wp-block-image size-large img-fluid"><img decoding="async" loading="lazy" width="1024" height="683" src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-1024x683.jpg" alt="" class="wp-image-9" srcset="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-1024x683.jpg 1024w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-300x200.jpg 300w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-768x512.jpg 768w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-1536x1024.jpg 1536w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-rovenimagescom-949587-2048x1365.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>


<p>Paragraph 1</p>
</div>


<div class="col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses">
<h2 class="wp-block-heading">Heading 1</h2>


<figure class="wp-block-image size-large img-fluid"><img decoding="async" loading="lazy" width="1024" height="640" src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-1024x640.jpg" alt="" class="wp-image-8" srcset="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-1024x640.jpg 1024w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-300x188.jpg 300w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-768x480.jpg 768w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880-1536x960.jpg 1536w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-531880.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>


<p>Paragraph 1</p>
</div>


<div class="col-12 col-sm-6 col-lg-3 WP-removeDefaultClasses">
<h2 class="wp-block-heading">Heading 1</h2>


<figure class="wp-block-image size-large img-fluid"><img decoding="async" loading="lazy" width="1024" height="576" src="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-1024x576.jpg" alt="" class="wp-image-7" srcset="http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-1024x576.jpg 1024w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-300x169.jpg 300w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-768x432.jpg 768w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-1536x864.jpg 1536w, http://voicesofthechurch.com/wp-content/uploads/2023/08/pexels-pixabay-220067-2048x1152.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>


<p>Paragraph 1</p>
</div>
</div>
</div>
</div>

我不知道为什么它的造型不正确,但也许有人可以帮助……
如果您需要任何其他的东西,请让我知道,我会提供进一步。要查看现场,请访问VoicesOfTheChurch.com。这是目前页面上唯一的东西。

pbgvytdp

pbgvytdp1#

在朋友的帮助下,我们找到了问题所在并想出了解决办法。WP是添加了一些其他wp标签,我从来没有想到会导致问题。我张贴这只是为了以防万一它可能对其他人遇到同样的问题有帮助。我想继续在JavaScript上工作,使它变得更好;但是,它开始了!

var WPclasses  = [
  "is-layout-constrained",
  "is-layout-flex",
  "is-layout-flow",
];  

$(".WP-removeDefaultClasses").removeClass (function (index, className) {
  return (className.match (/\bwp-\S+/g) || []).join(' ');
}).removeClass(WPclasses);

这会查找Wordpress添加的所有wp-标签,并将其全部删除,仅在您指定的“容器”中,以便您可以在自定义块中的子元素(如图像和段落)和其他块中使用wp-标签。完全控制你想要控制的区域,而不是你想要WordPress控制的区域。我不得不添加一些自定义标记,这些标记被分类在WPclasses数组中。简单,但有效!

相关问题