Category: WordPress

Add class on categories widget for post counter styling

function rm_categories_post_count_filter ($cat_post_count) {
    $cat_post_count = str_replace('(', '<span class="post_count pull-right"> (', $cat_post_count);
    $cat_post_count = str_replace(')', ' )</span>', $cat_post_count);
    return $cat_post_count;
}
add_filter('wp_list_categories','rm_categories_post_count_filter');

Limiting WP Post content and adding conditional Read More button

Content limit 110 words.

<?php $trimexcerpt = get_the_content();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 110, $more = ' [...]' );
echo "<p>" .$shortexcerpt. "</p>";
?>

After 110 words show “Read More”

<?php
$count = str_word_count($shortexcerpt);

if($count >= 110){ ?>
    <a href="<?php the_permalink(); ?>" class="st-more-link text-center
 text-uppercase"><span><?php _e('Read More', 'cherry') ?></span></a>
<?php } ?>

How to use wp_kses function

<?php
 $copyright = get_theme_mod('kotha_footer_copyright');

 $allowed_tags = array(
    'strong' => array(),
    'a' => array(
       'href' => array(),
       'title' => array()
    )
 );
 echo wp_kses( $copyright, $allowed_tags ); ?>

More info