Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Eric, i now realize why i ran into this issue which seems so unlikely to occur since post content is unlikely to be under 155 characters. I had already made another slight change to your original function that allows for the meta description to be pulled from the manual excerpt that can be added to posts rather than just from the post content.

    I replaced “$descrip = strip_tags($post->post_content);”
    with
    “if ($post->post_excerpt == “” ) : $descrip = strip_tags($post->post_content);
    else :
    $descrip = strip_tags($post->post_excerpt);
    endif;”

    In this case when you add an appropriate length manual excerpt to the post it would then appear in the meta description without the last word.

    Sorry for the confusion.

    Thanks ericr23. Now i understand the goal of the code snippet.

    But wouldn’t it be better to only pop that last word after you’ve tested to see whether the description exceeds 155. By replacing the “mandatory” array_pop with the conditional version below the last word will only be dropped if the original excerpt is known to have exceeded 155 characters; otherwise it $descrip will keep the full excerpt intact.

    if ($descrip_more == ‘ …’) {
    array_pop($descripwords);
    }

    Thanks for making me understand this better. I hope my addition is an improvement. It seems to work as it should.

    This excerpt function seemed to work for me when I initially used it in my header but then I found that the last word from the excerpt kept vanishing. To fix it I removed the line “array_pop($descripwords);” which pulls off the last element of the $descripwords array.

    After removing that line the function works as i originally expected. I’m just curious why that line is part of the function in the first place. What is its purpose? Just looking to understand it more thoroughly.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)