Saltar navegación

[Resuelto] Limit the number of characters in WYSIWYG with links

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to limit the number of characters in WYSIWYG editor for anchor tags links

Solution:
You need to add custom shortcode as per your requirement to restrict the number of characters for anchor tag links inside the WYSIWYG editor.

You can find proposed possible solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/limit-the-number-of-characters-in-wysiwyg-with-links/#post-617556

Relevant Documentation:

This support ticket is created hace 6 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Etiquetado: 

Este tema contiene 7 respuestas, tiene 2 mensajes.

Última actualización por PZ hace 6 años, 10 meses.

Asistido por: Minesh.

Autor
Mensajes
#616533

PZ

Hello, I need a bit more help with the code from this thread:
https://toolset.com/forums/topic/limit-characters-display-in-view-for-custom-wysiwyg-field/

The code works if the characters in the wysiwyg field are not links... but mine are links. What shall I change in the code to make it work for links?

Thanks.

#616617

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - what you mean when you say you have links with wyswyg?

Could you please share screenshot?

#616635

PZ
Zrzut ekranu z 2018-02-16 08-23-04.png

Sure.

#616658

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Well - is it possible for you to send me access details and problem URL where you've added the limit character shortcode so I can check what's going wrong there.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#617348

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Well - I would like to know here:

Will your author field have only one author with one anchor tag respectively - as I understand you want to restrict the author name - correct?

What if you try to use following code in order to get anchor tag caption:

 preg_match_all('/<a .*?>(.*?)<\/a>/',$content,$matches);
#617401

PZ
Zrzut ekranu z 2018-02-19 13-06-19.png

Actually, sometimes I have more than one author in that field and what I want to limit is the overall number of characters. Like in the attached screenshot.

And I'm not sure where to put this code you gave me...

#617556

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Could you please check now. I've adjusted the shortcode as given under:

add_shortcode('limit_content', 'trim_shortcode');
 function trim_shortcode($atts, $content = '') {
    $content = wpv_do_shortcode($content);
    $length = (int)$atts['length'];
  
    preg_match_all('/<a .*?>(.*?)<\/a>/',$content,$matches);
  
   
   
    $content = join(" ",$matches[1]);
   
   
    if (strlen($content) > $length) {
        $content = substr($content, 0, $length) . '…';
    }
  
    // Strip HTML Tags
    $content = strip_tags($content);
  
    return $content;
}
#617567

PZ

Works!!! Thank you sooooo much 🙂 You're amazing.