Customise post meta on specific widgets

Community Forums Forums Design Tips and Tricks Customise post meta on specific widgets

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  braddalton 1 year ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #53118

    Ben @ Advice Media
    Post count: 97

    I want to display a custom post meta on posts in select widgets.

    I found a great piece of code by Travis Smith at WPSmith that sort of lets me do it.

    / Customize the post meta function
    remove_action( 'gfwa_after_post_content', 'gfwa_do_post_meta', 10, 1 );
    add_action( 'gfwa_after_post_content', 'fm_do_post_meta' );
    function fm_do_post_meta( $instance ) {
    	if ( $instance['custom_field'] == 'featured' )
    	// Add Post Meta
    	$post_meta_featured = '[post_author_posts_link before="by "]<br /> [post_date] [post_categories before="in "]'; //no space after initial bracket
    	printf( '<p class="post-meta-featured">%s</p>', do_shortcode( $post_meta_featured ) );

    I’ve customised it for my needs.

    However, the code is designed to output the customised post meta on every widget except the one that has featured in its $instance box.

    I got around this by putting featured in the $instance box of every widget except the ones I wanted it to display in.

    However, it also displays in post meta section of the posts, which I don’t want it to.

    As far as I see, there are two ways that I should be able to solve this.

    Edit the conditional code to display it only on those widgets where the $instance value is featured – or – add an addition condition that prevents the new post-meta function from displaying on single posts.

    Problem is, I’m not sure how to do either.

    Any help would be very much appreciated!


    Post count: 9192

    if ( !is_single()

    This will return false and prevent the code from executing on single posts.

    You could add classes to the widgets and use CSS also.

    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.