Use PHP string functions like substr to return a number of characters rather than word count.
The post content aaaaaaaaaaaaaaa aaaaaaaaaaaaa
will be much longer than a a
.
$max_length = 150;
echo substr( $string, 0, $max_length );
As a function it might look like:
function string_limit_words( $string = '', $count = 25, $after="..." ) {
if ( strlen( $string ) <= $count ) {
return $string;
}
return substr( $string, 0, $count ) . $after;
}
echo string_limit_words( "This is a lot of words", 10 );
// This is a ...
the_excerpt()
prints the output while get_the_excerpt()
will return the string to allow manipulation before output.
Related Posts:
- How to Add Image to WordPress RSS-Feed with no Plug-in?
- Disable comment rss feeds for pages in wordpress
- Getting Post Thumbnail from RSS feed with SimplePie
- Limiting the WordPress feed to only a certain limit of characters
- Editing Category RSS Feeds
- Remove a div from RSS feed
- get post content of particular post by url
- Display image from an external rss feed on wordpress without plugins
- Can’t retrieve element with WordPress default @fetch_rss();
- Include only posts with meta key “add_in_rss” in RSS Feed
- Can I add the post featured image to a specific RSS feed?
- change default RSS feed URL
- Display WordPress Post on A Different Site
- Aspx/Rss feed – failed to open stream: Redirection limit reached
- Good RSS Feed Parser to use on php file?
- Disable category RSS Feeds on WordPress blog with PHP
- How to access all meta data for RSS feed?
- WordPress create custom XML RSS feed template
- A custom RSS feed link, how do I modify the XML structure?
- How to find cause of PHP notices with no stack trace?
- The correct method to pass query vars in AJAX using ajaxurl
- How to paginate a list of custom taxonomy terms?
- Display user’s total comment count outside The Loop
- reason of splitting theme files to multiple files
- wordpress separate registration for different roles
- How to get user by display_name with WP_User_Query
- Changing Link Attributes for Wp_Link_Pages
- Problem with Woocommerce REST API Authentication
- How to get custom image size for image uploaded in Customizer
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- How to change
- Passing POST data from one WP post to another
- Call to undefined function issue
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- How can I generate random numbers inside my shortcodes on each implementation?
- How to create a custom category of wordpress admin
- WordPress automatically adding html tag around PHP code
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Customizer: Output default value in Customizer CSS
- Converting HTML Template to WordPress Theme
- PHP Warning: chmod(): Operation not permitted in class-wp-filesystem-direct.php on line 173
- Saving an array of dynamic repeater data as post_meta
- Image rotation and editing stopped working in WordPress after upgrading Ubuntu from 16.04 to 18.04
- WordPress asks you for your FTP details if you want to run Automatic Updates/Upgrade Plugins
- Populate editor with some content of a page with a page template
- 404 error when I acess the second page of post-type
- Trying do build a contact form
- How to Disable WordPress Page Revisions?
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- Prev/Next Links Broken on Static Front Page Pagination
- How to integrate noimage picture in this code
- get comment data using comment id
- How to add no follow to specific links?
- WordPress transient not working with WP Engine
- Basic wpdb update question
- Only show size attributes in product box woocommerce when available
- Can I set up a hover animation in CSS depending on a PHP conditional?
- WP check_ajax_referer() is not working
- How to access or parse key/values that have “string”
- WordPress upload file size error even after raising php limits
- Function for simple math doesn’t work what am I doing wrong? [closed]
- Will I have problem with PHP 5.5 and WordPress 4.9.4?
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- Trying to run website a php file is blank
- Create condition for Author bio Social Links
- How do I Populate a Table Field with User Meta Data?
- Redirecting visitor from foreign domain with WP content as referrer
- wp_query – Exclude the first thumbnail from lazy loading on archives
- Change lost password url to a mailto URL in WordPress
- Usermeta data unserialize, extract and display in table in WordPress
- Exclude category from woocommerce product category list
- How to use a variable (for wordpress postid) in other queries?
- How to let mobile navigation menu close when link is clicked?
- How to transfer variables from one function to another [closed]
- Displaying SQL query result from user input via wpdb
- Display specific page if user signed in
- wordpress dependent dropdownlist using post type is not working
- How to insert text into post based on category – via single.php file
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- str_replace not preserving whitespace
- customizer live preview layout picker
- Display tab title as ‘blog tagline | blog title’
- Conditional statement within WP SQL query
- Modify category archive page loop on functions.php
- How to display html code on homepage
- two wordpress sites, two themes, one database, same content
- Check if values exists DB
- Trying to exclude posts from a category on the home page
- Php conditional help needed
- Adapting a php array to WordPress
- Different layout on search page depending on category post
- WordPress and magic quotes
- Dynamically pull the correct email address from a match
- Issues trying to add a href statment with PHP into a PHP Echo Statement [closed]
- Help with if/else loop [closed]
- How to execute a shortcode within a custom field?
- using custom pages for myaccount in woocommerce
- Putting form result in my database