• I’m looking that the template files and the thread at https://www.ads-software.com/support/topic/how-to-remove-post-meta-from-single-post and cannot figure how to remove post meta. Like the OP in this thread, I am using a child theme.

    I thought I understood the response and added a conditional for only single pages of a custom post type.

    add_action( 'init', 'ltg_remove_meta' );
    function ltg_remove_meta() {
    	if ( is_singular('li_author') ) {
    		remove_action( 'storefront_single_post', 'storefront_post_meta', 20 );
    	}
    }

    Even without the conditional, the action does not work.

    What am I doing wrong?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi dianat

    If you are already using child theme then remove above code you have added and try pasting below code instead in functions.php file in child theme.

    function storefront_posted_on() {
    		if(!is_single()){
    			$time_string = '<time class="entry-date published updated" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s" itemprop="datePublished">%4$s</time>';
    		}
    
    		$time_string = sprintf( $time_string,
    			esc_attr( get_the_date( 'c' ) ),
    			esc_html( get_the_date() ),
    			esc_attr( get_the_modified_date( 'c' ) ),
    			esc_html( get_the_modified_date() )
    		);
    
    		$posted_on = sprintf(
    			_x( 'Posted on %s', 'post date', 'storefront' ),
    			'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    		);
    
    		$byline = sprintf(
    			_x( 'by %s', 'post author', 'storefront' ),
    			'<span class="vcard author"><span class="fn" itemprop="author"><a class="url fn n" rel="author" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span></span>'
    		);
    
    		echo apply_filters( 'storefront_single_post_posted_on_html', '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>', $posted_on, $byline );
    		}
    
    	}

    Let us know if any confusion.

    Best Regards!!!

    Thread Starter dianat

    (@dianat)

    Thanks so much for responding. Unfortunately, this isn’t what I’m looking for.

    I am trying to remove meta for a custom post type, li_author, specifically on the single page. While I’m not fluent in PHP, it does not look like this code is removes meta.

    Even when I change the !is_single() conditional in your code to is_singular(‘li_author’), the post metadata remains on the individual CPT page.

    Any ideas how to achieve the removal of meta in this context?

    Your code looks spot-on, it’s hard to diagnose why this isn’t working :/

    No other customisations / plugins that might interfere with this?

    I know it’s not an ideal workaround but you could always hide the content with css.

    Thread Starter dianat

    (@dianat)

    Thanks, James, for responding. I am hoping to avoid hiding with CSS.

    Very strange. I tested this as the only snippet, without the conditional, in functions.php of a child theme, deactivated all plugins except WC, and removed all styles and custom templates. I even switched to storefront itself and placed the snippet in its own functions.php (setup.php, extras.php). No joy.

    I hate to ask … are you sure this works?

    I see the problem now. The init hook is too early in this case. Try using wp instead.

    Cheers.

    Thread Starter dianat

    (@dianat)

    Thanks, James, for all your help.

    Tried this at https://likethegoddess.info

    add_action( 'wp', 'ltg_remove_meta' );
    function ltg_remove_meta() {
    		remove_action( 'storefront_single_post', 'storefront_post_meta', 20 );
    }

    No joy.

    @dianat / @jameskoster

    I’m not a fan of CSS hacks, but this’ll work

    .entry-header .byline {
        font-size: .857em;
        display: none;
    }

    …..shouldn’t we be aiming for

    storefront_posted_on

    Thread Starter dianat

    (@dianat)

    Thanks for your feedback, Brad. Yes, we have discussed hiding the CSS. I would much rather get the hook to work if that’s possible.

    Correct me if I’m wrong, isn’t storefront_posted_on for the post date only? In Storefront, post meta is “Posted on [DATE] by [AUTHOR].” I need to eliminate all post meta.

    Has anyone successfully be able to use this?

    add_action( 'wp', 'ltg_remove_meta' );
    function ltg_remove_meta() {
    		remove_action( 'storefront_single_post', 'storefront_post_meta', 20 );
    }

    Instead of hooking into init or wp you need to hook into template_redirct

    add_action( 'template_redirect', 'marce_remove_storefront_entry_meta', 20 );
    
    function marce_remove_storefront_entry_meta() {
          remove_action( 'storefront_single_post', 'storefront_post_meta', 20 );
    }
    Thread Starter dianat

    (@dianat)

    Thanks for posting, Mikey. Unfortunately, changing from wp to template_redirect isn’t removing post meta.

    Even switching to Storefront itself, using no plugins, trying init, wp, and template_redirect, no joy.

    Hi dianat,

    My bad, the code above I wrote only applied to the single post, not to the front page. This will remove it from the front page but not from the single post page.

    add_action( 'init', 'marce_remove_storefront_entry_meta', 20 );
    
    function marce_remove_storefront_entry_meta() {
          remove_action( 'storefront_loop_post', 'storefront_post_meta', 20 );
    }

    Finally! ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Remove post meta from single blog page’ is closed to new replies.