• Resolved mandirao

    (@mandirao)


    Greetings! Preamble with standard “I’m a kind of a newb” admission…

    Does anyone know of a way to show the post subheadings underneath the title on my enabled post excerpts? I’ve been digging everywhere to no avail.

    Thus far I’ve enabled thumbnails, allowed for custom excerpt styling, and put in a read more link as per the following code. Can I drop in ‘the_subheading’ somewhere? Or write a new function? Please and thank you!

    <?php add_theme_support('post-thumbnails'); ?>
    <?php //allow custom css styling in excerpts
    	function improved_trim_excerpt($text) { // Fakes an excerpt if needed. Solution via https://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/
      	global $post;
      	if ( '' == $text ) {
        	$text = get_the_content('');
        	$text = apply_filters('the_content', $text);
        	$text = str_replace('\]\]\>', ']]>', $text);
        	$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
        	$text = strip_tags($text, '<p><big><strong><small><em><i><h1><h2><h3>h4><h5><h6>');
        	$excerpt_length = 50;
        	$words = explode(' ', $text, $excerpt_length + 1);
        	array_pop($words);
        	array_push($words, '...');
        	$text = implode(' ', $words);
        	$text = force_balance_tags( $text );
    
      }
    return $text;
    }
    ?>
    <?php //automatically add a "read more" link below both automatically and manually created excerpts
    function excerpt_read_more_link($output) {
     global $post;
     return $output . '<a class="read-more" href="'. get_permalink($post->ID) . '"> Read More</a>';
    }
    add_filter('the_excerpt', 'excerpt_read_more_link');
    ?>
    <?php remove_filter('get_the_excerpt', 'wp_trim_excerpt'); ?>
    <?php add_filter('get_the_excerpt', 'improved_trim_excerpt'); ?>
    <?php //begin cat-tag filter for tag widget for single posts. Solution via https://www.transformationpowertools.com/wordpress/edit-widget-parameters-filter-wordpress
    	//still looking for a solution to filter tag cloud on custom pages featuring a post loop/feed
    	add_filter('widget_tag_cloud_args','cat_tag_cloud_tags');
    	function cat_tag_cloud_tags($args) {
    	if( is_single() ) {
    		global $post;
    		$post_tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
    		$args = array('include' => implode(',',$post_tag_ids));
    	}
    	return $args;
    	}
    ?>

    https://www.ads-software.com/extend/plugins/subheading/

Viewing 1 replies (of 1 total)
  • Plugin Author Steve

    (@stvwhtly)

    Hi,

    Although untested, it should be possible to add the subheading to the excerpt via the improved_trim_excerpt function:

    function improved_trim_excerpt($text) {
    	global $post;
    	if ( '' == $text ) {
    		...
    	}
    	$text = get_the_subheading( $post->ID, '<p>', '</p>' ) . $text;
    	return $text;
    }

    This would wrap the subheading in <p> tags and output it before the excerpt.

Viewing 1 replies (of 1 total)
  • The topic ‘Display Subheading in Excerpts’ is closed to new replies.