Depending on where in the loop you call excerpt()
wpautop might be creating the <p>...</p>
wrapper. In that case, you could wrap $excerpt
with <p>...</p>
before returning it.
Edit: Try this approach <?php echo excerpt(25)."\n";?>
(or possibly "\n\n"
) to change the behavior.
in function awesome_excerpt()
you have $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
So, $text
will have to contain a beginning <p>
. That is likely causing what you describe. Add str_ireplace('<p>', '', $excerpt)
in function excerpt()
before calling explode
.
In the current code shown in your question it’s unclear where function excerpt()
is being called.
Why not just use the excerpt_length
filter to modify the length of the excerpt? From the Codex:
function custom_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
Related Posts:
- Word Count Function Preventing Permalink Editing
- Custom excerpt function re-factoring
- How to remove the excerpt in the Dzonia Lite theme
- How to put “Read more” link in Custom Excerpt inside p tag?
- Error when adding excerpt to the content through functions.php
- Query Pages and post excerpts dynamically
- My custom get_the_excerpt() can’t get excerpt by ID
- How to remove the space before the ellipsis in excerpt?
- How to trim content AND retain HTML?
- Cleaning up WordPress to improve performance?
- List of all theme customizer control types?
- Modify previous and next text from pagination links
- How can I modify the permalink via a filter?
- wp_set_object_terms and arrays
- Shortcode putting html such as
- How to return the_excerpt (without echo)?
- How to get the original price of the product in woocommerce?
- How to use WordPress (PHP) functions in AngularJS partials files?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- enqueue multiple Google fonts with multiple weights and styles (italic)
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- How to check If Oembed is empty or not
- What is the fastest way to load PHP functions that are only used in one theme template?
- Can’t load WP function into external function
- Image as Sales Badge
- WSoD being caused by this piece of code
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- How to complete two other input fields, completed the first
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Css loads very slow [closed]
- Show when user is online/offline in real time on user_profile.php
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- How do I link a button I created in theme customizer to a function?
- Call to undefined function get_userdata() in plugin
- jQuery code not working when included in functions.php
- Fatal Errors on pluggable.php
- Log in / Log Out Custom Button
- how to test for all children (including multilevel grand-childern) of page
- Dilemma of Populating all the categories in a drop down list
- Add item to top of menu using a filter in functions.php
- Can’t save php string to a custom field
- Limit Taxonomy Output in Conditional Statement
- wp_redirect only works on main site and not on other sites
- get_template_directory adding FTP root folders in urls
- Fatal error: Call to undefined function register_new_user()
- stripping tags from excerpt in WordPress is not working
- How to modify the default feed via a function
- require_once() if a product in woocommerce contains a tag [closed]
- Loop over Array and get the distinct ids
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Shortcode for Listing Users from Meta Value?
- Post not populating for custom post type based on category selection
- Display css ONLY on most recent post of specific category?
- call_user_func_array() expects parameter 1 to be a valid callback, function ‘———-‘ not found or invalid function name
- How can I use custom menus with a Bootstrap WordPress theme?
- Dynamic Menu drops pages?
- Aspx/Rss feed – failed to open stream: Redirection limit reached
- Adding an Unlinked Space in a Custom Function
- How do I call an external php non WordPress class into functions.php?
- send popup after wp_redirect()
- How to remove/hide collapse menu for user/subscriber?
- How to implement __() function in my theme’s php file?
- Database entry removed on browser refresh, Ajax PHP jQuery
- Checkbox doesn’t save inside metabox
- A function to get the content of a page
- Add Featured Image to Existing Post
- How to get latest post ID in functions.php?
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Get current user id in function php
- How can I prevent a shortcode div from extending beyond its boundaries?
- Get custom field value from the function.php
- Non-blocking file_put_contents in function.php
- Display a custom name when the user has no name settle in his account
- Advance custom fields variable with if statement & Function
- Restrict wordpress access to logged users only
- Discount in the specific product title using keyword ( Woocoommerce )
- Modify post image in full size
- Woocommerce textarea format ignored
- How best to check if a user is from China and hide content?
- Menu to the right of screen on desktop using Bootstrap 4
- Printing OEmbed URL based on Post selected w/o page refresh
- Automatically refresh page if widget is added to page?
- Using Tag Groups: Displaying groups and adjacent tags of current post
- My query keeps looping infinitely ! how to stop it?
- How to create “page” used for generating PDF? [closed]
- Published custom posts missing
- PHP version or config prohibiting script from working properly
- Why isn’t my custom function kicking in from my functions.php file?
- Shortcoding with Divs
- static array on functions.php
- ajax form function error
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to display the date under the post title?
- Simple Probléme in wordpress
- how to create twitter card without plugin in wordpress website?