Skip Navigation

[Resolved] create excerpt from custom field

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.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Marisa 5 years, 10 months ago.

Assigned support staff: Minesh.

Author
Posts
#345955

Need the copy and paste code to

A. shorten a custom field text to a specified amount of characters
OR
B. Create a custom excerpt that applies to a custom field (not to the default content editor).

on the output of the custom field using Views.

I've read about half a dozen help tickets but they are not exactly what I'm trying to do , or the one that looked like it was didn't work.

#345994

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Could you please try to add following custom shortcode to your current theme's functions.php file.

add_shortcode('limit_content', 'trim_shortcode');
 function trim_shortcode($atts, $content = '') {
    $content = wpv_do_shortcode($content);
    $length = (int)$atts['length'];
 
    if (strlen($content) > $length) {
        $content = substr($content, 0, $length) . '…';
    }
 
    // Strip HTML Tags
    $content = strip_tags($content);
 
    return $content;
}

And you can call it using your custom field. For example:

[limit_content length="140"][types field="your-field" output="raw"][/types][/limit_content]

I hope this will be exactly what you are looking for. If you still have any issues with above code, please do not hesitate to get in touch with me.

#346168
limit-content-length.JPG

Very similar to another support ticket I tried to follow. With the same results. See screenshot.

#346269

Never mind - it works. I had something wrong in the function before, and this time I think I hadn't uploaded it to the server.

<div class="slide-container">  <div class="slide-image" style=" background-image:url('[types field="case-story-image" size="full" url="true"][/types]');"></div>
  <a href="[wpv-post-slug]"><div class="slide-caption"><h2 class="case-story">[limit_content length="15"][wpv-post-title][/limit_content]</h2><div class="caption-copy">[limit_content length="150"][types field="case-story-text" output="raw"][/types][/limit_content]</br><span style="display:inline-block; text-align:right; color:#fff; float:right; text-decoration:underline;">read more</span>
    </div></a>
  <a href="[wpv-post-slug]">
    <h2 class="case-story mobile-caption">[wpv-post-link]</h2></a>
#346270
rose.JPG

and looks like this. If there is any way to recognize and not break a word easily, let me know. Otherwise, we're good.