Skip Navigation

[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, 1 mes. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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: 

This topic contains 7 respuestas, has 2 mensajes.

Last updated by PZ hace 6 años, 1 mes.

Assisted by: 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

Languages: Inglés (English )

Timezone: 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

Languages: Inglés (English )

Timezone: 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

Languages: Inglés (English )

Timezone: 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

Languages: Inglés (English )

Timezone: 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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.