• Resolved tizz

    (@tizz)


    Hi @camthor, sorry I’m still here because I’ve been trying for days to solve the problem of the too long description in tooltip (here) by myself, but I didn’t make it. Although I found many questions and answers that were close to mine, the case is specific and I haven’t been able to fit anything to my purpose, also because I know very little about PHP.
    The alternative is to use custom_title = "" to remove the description entirely, but importing locally some more content from the production site I realized that the lists will be full of terms because I would like to create a kind of music glossary, and so it would be better for the user to have some preview when hovering, instead of a lot of “dumb” links, without being forced to open many of them, and also to entice him to continue reading.

    I like your plugin because it is simple and does what it does comfortably (e.g., I really like the ease with which you can create and then assign the group with the quick edit from the tag list), and with the choice of limiting the length of the description it would be perfect. It would be possible to do it with a filter? Something like

    function custom_excerpt_length( $length ) {
      if( ...() ) { 
        return "$number of words or characters, with ellipsis";
      }
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

    or with $max_len =, or wp_trim_words, or maybe – I don’t know if it is much more complicated since you have to change the code – with another parameter for the shortcode on the “custom title” as well as {name} etc., for an excerpt, or word / character limit in description?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please try this code:

    function tag_groups_sanitize_shorten_tag_title($title) {
      $number_of_words = 10;
      $title_no_html = wp_strip_all_tags( html_entity_decode( $title ) );
      $title_change_quotes = str_replace( '"', "”", wptexturize( $title_no_html ) );
      $title_shortened = implode( ' ', array_slice( explode( ' ', $title_change_quotes ), 0, $number_of_words ) );
      if ( mb_strlen( $title_shortened ) != mb_strlen( $title_change_quotes ) ) {
        $title_shortened .= '...';
      }
      return $title_shortened;
    }
    add_filter( 'tag_groups_tag_title', 'tag_groups_sanitize_shorten_tag_title' );

    It counts words that are separated by spaces. It’s very simple and may cut at places that don’t make sense, like the automatic WordPress excerpt.

    In the shortcode you use ... custom_title="{description}" ...

    I realize that you have to switch the setting “HTML in tag description” to “keep” for the filter to work but I will change that in a future version.

    Thread Starter tizz

    (@tizz)

    Fantastic! It works like a charm. Thanks again Chris.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Title attribute in tag description’ is closed to new replies.