Elementor Templates breaking page layout, is there any way to fix this issue except clicking on "Regenerate Files & Data" option in Elementor tools

huangapple go评论45阅读模式
英文:

Elementor Templates breaking page layout, is there any way to fix this issue except clicking on "Regenerate Files & Data" option in Elementor tools

问题

我通过自定义一些 Elementor 模板为我的网站创建了几个落地页。如果我编辑其中任何一个模板,经常会出现页面损坏的问题。现在,我可以使用 Elementor 工具的 "重新生成文件和数据" 选项来解决这个问题。但在每次修改时都这样做很麻烦。

我尝试停用我们在该网站上使用的所有插件,以查看是否有插件引起了这个问题,但事实并非如此。
在调查此问题时,我注意到只有使用 Elementor 模板的页面受到影响。

此外,服务器具有足够的内存,排除了任何缓存问题。

有没有办法修复损坏的页面布局问题?

英文:

I created several landing pages for my website by customizing a couple of Elementor templates. If I edit any of the templates, I frequently have broken page issues. Now, I can solve it by using the "Regenerate Files & Data" option of Elementor tools. But doing this on every modification is a hassle.

I tried deactivating all the plugins we are using on this site to check if any of the plugins were causing this issue, but that's not the case.
While investigating this issue, I noticed that only the pages using Elementor templates are affected.

Also, the server has enough memory which rules out any caching issues.

Is there any way to fix the broken page layout issue?

答案1

得分: 3

add_action('save_post', 'clear_elementor_cache');

function clear_elementor_cache() {
  // 检查是否加载了Elementor并且触发了钩子
  if (did_action('elementor/loaded')) {
    // 自动清除和重新生成Elementor CSS缓存
    \Elementor\Plugin::instance()->files_manager->clear_cache();
  }
}

Explanation

此函数响应"save_post"钩子,该钩子在保存或更新帖子或页面时触发。具体来说,该函数旨在在保存帖子或页面时自动清除并重新生成Elementor CSS缓存。

以下是代码执行的逐步解释:

使用add_action()函数将新的操作添加到"save_post"钩子。add_action()的第一个参数是要将操作添加到的钩子的名称,第二个参数是触发钩子时应调用的函数的名称。

clear_elementor_cache()函数被定义为在触发"save_post"钩子时调用的函数。此函数使用did_action()函数来检查是否已为特定钩子调用了操作。

如果Elementor已加载并且已触发了钩子,则会调用Elementor文件管理器的clear_cache()方法。此方法会清除并重新生成Elementor的CSS缓存。

最后,由于将操作添加到"save_post"钩子中,因此每当保存帖子或页面时,都会自动调用clear_elementor_cache()函数。

总的来说,此函数有助于确保对Elementor小部件或页面布局所做的更改会自动反映在网站前端,无需手动清除或重新生成缓存。

英文:
add_action('save_post', 'clear_elementor_cache');

function clear_elementor_cache() {
  // Check if Elementor is loaded and the hook has fired
  if ( did_action( 'elementor/loaded' ) ) {
  // Automatically purge and regenerate the Elementor CSS cache
    \Elementor\Plugin::instance()->files_manager->clear_cache();
  }
}

Explanation

This function performs an action in response to the "save_post" hook, which is fired whenever a post or page is saved or updated.
Specifically, the function is designed to automatically clear and regenerate the Elementor CSS cache whenever a post or page is saved.

Here's a step-by-step breakdown of what the code is doing:

The add_action() function is used to add a new action to the "save_post" hook. The first argument to add_action() is the name of the hook to which the action should be added, and the second argument is the name of the function that should be called when the hook is fired.

The clear_elementor_cache() function is defined as the function to be called when the "save_post" hook is fired. This function checks if Elementor is loaded and the hook has fired by using the did_action() function, which checks if an action has been called for a specific hook.

If Elementor is loaded and the hook has fired, the clear_cache() method of the Elementor files manager is called. This method clears and regenerates the CSS cache for Elementor.

Finally, the clear_elementor_cache() function is automatically called whenever a post or page is saved, due to the action being added to the "save_post" hook.

Overall, this function helps to ensure that any changes made to Elementor widgets or page layout are automatically reflected on the front end of the website, without the need for manual cache clearing or regeneration.

huangapple
  • 本文由 发表于 2023年2月8日 23:58:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388444.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定