0

All my teaser excerpts have no formatting applied to them. With firebug I can get the text to look how I want by editing the html but I don't know where to edit the html in wordpress. How can I do this? Thanks

3 Answers 3

1

wordPress does this by default. you can either use a plugin such as: http://wordpress.org/extend/plugins/advanced-excerpt/ http://wordpress.org/extend/plugins/the-excerpt-re-reloaded/

or write your own functions to remove the default filters from the_excerpt() such as: http://bacsoftwareconsulting.com/blog/index.php/wordpress-cat/how-to-preserve-html-tags-in-wordpress-excerpt-without-a-plugin/

3
  • caveat: this code bacsoftwareconsulting.com/blog/index.php/wordpress-cat/… does seem to leave broken html tags - tested with a <strong> tag.
    – Michael
    Feb 25, 2012 at 20:11
  • Thanks for the suggestions but I probably should have mentioned that I'm using the thesis theme therefore the plugin doesn't do the job. I found this code in the link you provided: $allowed_tags = '<p>,<a>,<em>,<strong>,<img>'; which sounds promising but I'm not sure how to implement it
    – Nick
    Feb 25, 2012 at 20:23
  • plugins don't work w/ thesis? i'm skeptical. Feb 25, 2012 at 23:45
1

@Michael: I wrote the tutorial you are referring to: http://bacsoftwareconsulting.com/blog/index.php/wordpress-cat/how-to-preserve-html-tags-in-wordpress-excerpt-without-a-plugin/

It does not leave any broken html tags, I use it on my blog. Unless the excerpt ends between the starting and ending tag. You need to make sure that your excerpt does not break whatever tag you are using. Check it out in the main page: http://bacsoftwareconsulting.com/blog/

@Nick: To answer the question on how to use the code of the reference above: Copy the "MAIN_CODE" and paste it in your "functions.php" file of the thesis theme. After that you need to replace line 22 of the "MAIN-CODE" with the "$allowed_tags" you want. For instance to allow p, a, em, strong and image, you replace Line 22: with $allowed_tags = '<p>,<a>,<em>,<strong>,<img>';

One of the things the code can't do is to add color or larger fonts. Like I said before, you always need to make sure that the excerpt does not end in between the opening and closing tags. You can also change lines 25 and 28 to your liking. The tutorial is self explanatory, but you need to spend on it few extra minutes.

Hope this Helps.

Boutros.

3
  • my apology if my remark caused any offence, however I am of the opinion that it should not be the user's task to make sure that the excerpt is not cutting through any html tag. that is the whole point of an automatic excerpt, and any coding to keep html tags in the excerpt should take care of this. I also looked this up myself in the past, and I am aware that this is no simple task. I have not checked if the 'advanced-excerpt' plugin can do this.
    – Michael
    Feb 25, 2012 at 23:40
  • i think there is a specific file/folder in thesis for custom functions (ie that won't get overwritten on upgrades), but since i don't use it i am not 100% certain. point being, for the OP to be careful posting things in functions.php w/ a theme like Thesis that will probably see updates Feb 25, 2012 at 23:46
  • I agree, for the thesis theme, you should refer to the documentation where to add user generated functions. It might be in a different place than "functions.php". Feb 26, 2012 at 20:06
0

Use remove_all_filters to remove filters on the_excerpt. Have a look at wp-includes/default-filters.php - a ton of filters are added to the_excerpt and get_the_excerpt which removes most of the formatting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.