更改 wordpress hestia 主题的首页 section 顺序

发布时间: 2018-03-12 17:07:55 作者: 大象笔记

由于用的是 hestia 免费版,没法使用自动调整首页 section 的功能。hestia 的 pro 版本确实太贵了,买不起。所以,我决定手动修改一下代码,以调整 section 的顺序。

通过查看 front-page.php 发现了 hestia_sections,grep 一下 hestia_sections,会发现不少的代码段

$ grep hestia_sections -r .

./inc/sections/hestia-about-section.php: add_action( 'hestia_sections', 'hestia_about', absint( $section_priority ) );

./inc/sections/hestia-shop-section.php: add_action( 'hestia_sections', 'hestia_shop', absint( $section_priority ) );

...

./front-page.php: do_action( 'hestia_sections', false );

add_action 与 do_action 的区别

add_action 的参数列表

看一下这行代码

if ( function_exists( 'hestia_about' ) ) {
	$section_priority = apply_filters( 'hestia_section_priority', 15, 'hestia_about' );
	add_action( 'hestia_sections', 'hestia_about', absint( $section_priority ) );
}

hestia_section_priority 是在哪里定义的呢? 我 grep 了所有代码,依旧没有发现。。。这不科学啊。

https://developer.wordpress.org/reference/functions/apply_filters/

apply_filters 相当于调用 add_filter 注册的函数。

把 15 调整成 150,你就会发现 about section 成功的到了页面最后。

我是一名山东烟台的开发者,联系作者