Support » Fixing WordPress » Problem with columns and custom fields/truncate function

  • I’ve set up twenty eleven as a child theme and created a custom page with advanced custom fields. I created a page with 2 columns and everything works great until I used truncated text.

    I use this code in my functions.php and it’s working as supposed to be:

    function trunc($phrase, $max_words)
    $phrase_array = explode(' ',$phrase);
    if(count($phrase_array) > $max_words && $max_words > 0)
    $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...'
    return $phrase;

    However, I’m experiencing a problem with my page when using this function in columns. As long as I am using the get_field alone without trunc, the columns look OK but as soon as I’m using trunc, I have a problem with the first column, second row moving over to the second column. You can check it here:

    Here’s the code I’m using in my template file (sorry for the spaghetti code but I’m new to PHP and WP):

Viewing 4 replies - 1 through 4 (of 4 total)
  • The problem is likely due to ‘broken’ HTML caused by simply counting words. That probably ends up having some opening tags with no corresponding closing tag.

    Here is an article with code for a custom excerpt function which will handle many of the problems:

    Unfortunately, this didn’t solve my problem. Instead I’m having two problems now: Same as before and foreign characters are not shown correctly (i.e. “ö” instead of “ö”). Any other idea what the problem could be?

    Ha! I was able to fix the issue about columns. But not about the foreign characters now showing correctly. Any ideas?

    It sounds like the DOMDocument is changing the character encoding. There may be a parameter to DOMDocument() for that, but I don’t know.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem with columns and custom fields/truncate function’ is closed to new replies.