Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Longkt/a1191a0e6a3c5439e65cb0e8a3cfb4de to your computer and use it in GitHub Desktop.
Save Longkt/a1191a0e6a3c5439e65cb0e8a3cfb4de to your computer and use it in GitHub Desktop.
function custom_onepress_display_page_title() {
if ( get_theme_mod( 'onepress_page_title_bar_disable' ) == 1 ) {
return;
}
$return = false;
if ( is_home() ) {
//$page_id = get_option( 'page_for_posts' );
$args = array(
'numberposts' => 1,
'order' => 'DESC'
);
$latest_post = get_posts( $args );
$page_id = $latest_post[0]->ID;
} else {
$page_id = get_the_ID();
}
$el = 'h1';
if ( is_singular( 'post' ) ) {
if ( ! apply_filters( 'onepress_single_show_page_header', false ) ) {
return;
}
$page_id = get_option( 'page_for_posts' );
$el = 'h2';
}
$apply_shop = false;
$is_single_product = false;
if ( onepress_is_wc_active() ) {
if ( is_shop() || is_product_category() || is_product_tag() || is_product() || is_singular( 'product' ) || is_product_taxonomy() ) {
$page_id = wc_get_page_id( 'shop' );
if ( is_product() ) {
$el = 'h2';
$is_single_product = true;
$apply_shop = get_post_meta( $page_id, '_wc_apply_product', true );
}
$return = false;
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
add_action( 'woocommerce_show_page_title', '__return_false', 95 );
}
}
if ( $return ) {
return;
}
$classes = array( 'page-header' );
$img = '';
$hide_page_title = get_post_meta( $page_id, '_hide_page_title', true );
if ( ! $is_single_product || ( $apply_shop && $is_single_product ) ) {
if ( get_post_meta( $page_id, '_cover', true ) ) {
if ( has_post_thumbnail( $page_id ) ) {
$classes[] = 'page--cover';
$img = get_the_post_thumbnail_url( $page_id, 'full' );
}
if ( onepress_is_transparent_header() ) {
$classes[] = 'is-t-above';
}
}
}
$excerpt = '';
if ( onepress_is_wc_archive() ) {
$title = get_the_archive_title();
$excerpt = category_description();
$term = get_queried_object();
$thumbnail_id = get_term_meta( $term->term_id, 'thumbnail_id', true );
$t_image = wp_get_attachment_url( $thumbnail_id );
if ( $t_image ) {
$img = $t_image;
}
} else {
$title = get_the_title( $page_id );
if ( get_post_meta( $page_id, '_show_excerpt', true ) ) {
$post = get_post( $page_id );
if ( $post->post_excerpt ) {
$excerpt = apply_filters( 'the_excerpt', get_post_field('post_excerpt', $page_id) );
}
}
}
if ( ! $apply_shop && $is_single_product ) {
$excerpt = '';
}
?>
<?php if ( ! $hide_page_title ) { ?>
<div class="<?php echo esc_attr( join( ' ', $classes ) ); ?>"<?php echo ( $img ) ? ' style="background-image: url(\'' . esc_url( $img ) . '\')" ' : ''; ?>>
<div class="container">
<?php
// WPCS: XSS OK.
echo '<' . $el . ' class="entry-title">' . $title . '</' . $el . '>';
if ( $excerpt ) {
echo '<div class="entry-tagline">' . $excerpt . '</div>';
}
?>
</div>
</div>
<?php } ?>
<?php
}
add_action( 'init', function() {
remove_action( 'onepress_page_before_content', 'onepress_display_page_title' );
add_action( 'onepress_page_before_content', 'custom_onepress_display_page_title' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment