You have a couple of issues here
-
the_content()
echos the content to screen. You should be usingget_the_content()
which returns the content. Just remember,get_the_content()
is unfiltered, so if you need filtered content, useapply_filters( 'the_content', get_the_content() )
which will return filtered content. -
Your
explode()
function is probably wrong as well. You are using a hyphen to explode your content into pieces of an array. If your content don’t contain hyphens, your array will only have one key with the complete content as value. You would probably need to use white spaces (explode( ' ', get_the_content() );
) or regular expressions or something similar to targt more than hypens or white spaces to explode the content. In one of my previous posts for custom excerpts , I have used something similar to explode my content, here is something you can try and experiment withpreg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', get_the_content(), $tokens); var_dump( $tokens );