wordpress - How to display only specific part of the_content(); text? -
is there way how trim content , display text within h2 tags in wordpress?
i trying display specific part of post content on specific page not whole of it. excerpt not work in case defined length. bet there simple way it... cannot find 1 yet.....
thank all.....
this can made in several ways, easiest :
function o99_filter_the_content_h2( $content ) { $pattern = "/<h2>(.*?)<\/h2>/"; preg_match($pattern, $content, $matches); return $matches[1]; } add_filter( 'the_content','o99_filter_the_content' );
add functions.php
file in theme.
note no longer h2 :-)
if use same other tag , can use more generic function:
function o99_filter_tags_generic($content, $tagname) { $pattern = "/<$tagname>(.*?)<\/$tagname>/"; preg_match($pattern, $string, $matches); return $matches[1]; }
where $tagname
tag filter
Comments
Post a Comment