I'm currently developing a website with WordPress 3.5 and I need to retrieve Post Text (Only text, not include images) at Archive Page. I can retrieve it with wp_excerpt() method without any problems. But the main problem for me is that I can't get the exact text layout. wp_excerpt() method returns text which ignores all extra spaces and line breaks. What should I do? I think I will get Only Post Text with Exact Layout if I can retrieve from wp_content() method. Thanks in advance for your help!
Tell me more
×
WordPress Answers is a question and answer site for
WordPress developers and administrators. It's 100% free, no registration required.
|
|
|||
|
|
|
There's not a native WordPress function to retrieve text only, but you can use WordPress filters and regex code to target this specific problem. To get unformated text, use get_the_content() function. To apply all filters, use it this way( see codex: http://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage ):
Before applying filters, there is a space for you custom modifications, e.g. removing images. This way:
Source of preg_replace code: http://www.phpzag.com/php-remove-image-tags-from-a-html-string-with-preg_replace/ You may need to remove also shortcodes, if any are used. This can be done also via preg_replace and I bet you'll find some on the google. |
|||
|