父主题功能具有条件-覆盖,删除还是过滤?

时间:2019-10-12 21:36:38

标签: function themes wordpress-hook

父主题将类添加到HTML元素。该功能中有针对不同页面/帖子类型的条件。

我想更改发布/页面的条件,以便它仅添加发布的类,而不添加页面的类。

我不是程序员。到目前为止,这项研究给我带来了更多问题,我需要您的帮助。

我尝试覆盖父级...因为这似乎比“删除并取消钩接”容易。

父功能

function underboot_post_classes( $classes ) {
    $classes[] = ( has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail' );

    if ( is_front_page() || is_home() || is_archive() ) {
        $classes[] = 'post-preview';
    }

    if ( is_singular( array('post', 'page') ) && ! is_front_page() ) {
        $classes[] = 'card mb-4';
    }

    if ( is_home() || is_archive() ) {
        $classes[] = 'card mb-4';
    }

    return $classes;
}
add_action( 'post_class', 'underboot_post_classes' );

尝试了具有较高优先级的此子功能

function child_underboot_post_classes( $classes ) {
    $classes[] = ( has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail' );

    if ( is_front_page() || is_home() || is_archive() ) {
        $classes[] = 'post-preview';
    }

    if ( is_singular(post) ||  && ! is_front_page() ) {
        $classes[] = 'card mb-4';
    }

    if ( is_singular(page) ||  && ! is_front_page() ) {
        $classes[] = '';
    }

    if ( is_home() || is_archive() ) {
        $classes[] = 'card mb-4';
    }

    return $classes;
}
add_action( 'post_class', 'child_underboot_post_classes', 25 );

孩子的功能引起“技术现场困难”

重载是完成此任务的好方法,还是将其删除和解除钩连是更好的解决方案?

0 个答案:

没有答案
相关问题