R
R
Rebldomakr2018-03-09 22:26:30
WordPress
Rebldomakr, 2018-03-09 22:26:30

How to limit header length in WordPress?

I want to limit title length only in Recent Posts. I have the Recent Post Extended plugin, maybe this plugin has such a function, I don't know. Tell me how it can be done
5aa2df4c50c8a319294180.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2018-03-09
@azerphoenix

Hello.
I won’t tell you how specifically for the plugin to limit the length of the title, but this option works for regular posts:
Add to functions.php

// длина заголовка
function the_title_excerpt($before = '', $after = '', $echo = true, $length = false) 
  {
    $title = get_the_title();

    if ( $length && is_numeric($length) ) {
        $title = substr( $title, 0, $length );
    }

    if ( strlen($title)> 0 ) {
        $title = apply_filters('the_title_excerpt', $before . $title . $after, $before, $after);
        if ( $echo )
            echo $title;
        else
            return $title;
    }
}

In the post (in the post template) respectively use:
In theory, in the widget of this plugin, you can change the output of the title from the_title to the above option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question