WordPress.org

Forums

Events Manager
[resolved] truncate string length for #_EVENTLINK (4 posts)

  1. raskull
    Member
    Posted 2 years ago #

    Hi... I would like to restrict the string length display of #_EVENTLINK to x characters max. How shall I do this?

    http://wordpress.org/extend/plugins/events-manager/

  2. mukesh panchal
    Member
    Posted 2 years ago #

    use this function

    function trimStringToFullWord($length, $string) {
    if (mb_strlen($string) <= $length) {
    $string = $string; //do nothing
    }
    else {
    $string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length));
    }
    return $string;
    }

  3. raskull
    Member
    Posted 2 years ago #

    Thanks for your help! I do need to know how to filter it for Events Manager. This is what I tried, and it seems to work. But I have no idea what I am doing. Can you let me know if the world will end:

    function my_em_event_placeholder( $replace, $EM_Event, $result ){
    	if ( $result == '#_EVENTLINK' ) {
    		$event_link = esc_url( $EM_Event->get_permalink() );
    		$event_shortname = substr($EM_Event->event_name, 0, 30 );
    		if ( strlen( $EM_Event->event_name ) > 30 ) $event_shortname .= '&hellip;';
    		$replace = '<a href="' . $event_link . '" title="' . esc_attr( $EM_Event->event_name ) . '">' . esc_attr( $event_shortname ) . '</a>';
    	}
    	return $replace;
    }
    add_filter( 'em_event_output_placeholder', 'my_em_event_placeholder', 1, 3 );
  4. agelonwl
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.