Try this. First check if the original string length is less than or equal to passed in length, and if so, we ignore the $after
parameter :
function the_titlesmall($before="", $after="", $echo = true, $length = false) { $title = get_the_title();
if( strlen($title) <= $length )
$after="";
if ( $length && is_numeric($length) ) {
$title = substr( $title, 0, $length );
}
if ( strlen($title)> 0 ) {
$title = apply_filters('the_titlesmall', $before . $title . $after, $before, $after);
if ( $echo )
echo $title;
else
return $title;
}
}
Related Posts:
- Remove “Private” + “:” in title does not work
- get_title without filter(the_title)
- How do I hide the current page’s title?
- WP action/filter to modify title before header output and article output?
- Don’t see add_filter result in the site front page
- Access get_the_title() from ‘excerpt_length’ filter
- Strip $before & $after strings from a page title
- Filter the title to only affect the_title() template function
- Modify WordPress Page Title ()
- Adding Filter | Page Title | Template | Why the_title affecting on menu?
- Hide H1 Title using the_title filter
- How to show page content in feed?
- Sanitize and data validation with apply_filters() function
- How many filter/action hooks are healthy?
- remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types
- Valid characters for actions, hooks and filters
- How to hook into unregistering a widget instance?
- How do I use the ‘http_request_host_is_external’ filter
- get_option() filtering and getting out of recursion
- AJAX filter posts on click based on category
- Can I add custom meta for each image uploaded via media-upload.php?
- How do I know if author field was changed on post save?
- Load different template file when condition met?
- Some questions regarding filter
- Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category
- Too many actions/filters!
- Which hook is fired when inserting media into a post
- How can override a add_filter of a plugin?
- Adding Filter Conditionally Per Page ID
- How to specify which category of the post to use in case of multiple categories
- Nested calls the the_content filter
- How to change domain used when pinging sites
- return values from hooks do_action and apply_filters, which is better
- Filter get_the_title to remove certain characters?
- Return a custom value in a function added to an action hook
- Using Conditional Statement in functions.php
- How can filters be run when they are never applied?
- Multiple filters for wp_get_archive
- Filter and modify entry-footer link in twentyseventeen
- Function the_content not working
- Is there a filter called ‘network_admin_init’?
- Break out of wordpress filter
- Manipulating show_on_front, page_on_front, page_for_posts and template hierarchy
- Are there actions or filters I can use for Ajax calls?
- Post Content, Special Characters and Filters
- Add filter problems
- Where is the content cache when using apply_filters(‘the_content…?
- No ‘Access-Control-Allow-Origin’ header is present [closed]
- How to prepare WordPress Rest data for Preview Changes?
- How to validate recaptcha on comments form?
- Does a plugin with a AJAX button filter exist? [closed]
- Is there any filter to trigger as soon as media is uploaded to post or page?
- Filtering the post list in the admin area
- add_filter with retrieve_password_message() not working in plugin, but works in functions.php
- Add a div of content within the_content after a certain block
- Gutenberg Block – Post Featured Image Filter Hook
- separate categories with comma and srounded by single quote
- Prevent add_filter being applied to wp-admin pages
- Translate custom order status through a filter?
- Using preg_replace() with the_content filter
- apply_filters(‘get_the_content’, $content) + Except
- Filter everything from content except output of a shortcode
- Is there a way to globallly apply esc_html( … ) to all inputs and anchors to filter out XSS markup?
- Filter get_page_by_path()
- Handle multiple parameters in filter
- Want to use wp_get_current_user() in query filter
- WP 4.5 hide core customizer sections
- Problem with Class, Filters and Callbacks
- Renaming wordpress login and get new password button
- Parse a shortcode differently based on on what it’s nested in
- return get_the_tag_list with whitespace removed
- How to redirect template_directory to subdomain relativ url?
- How do I add tags to entire comments, not just their text
- Modify author url display in edit-comments.php
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Filter Post Title without affecting screen-reader-text
- How to add lazy field in content endpoint using Gutenberg blocks
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- Widget image reorganize layout
- Re-order search results with posts_orderby filter and post meta value
- Set Microsoft Word links to open in new window/tab
- WordPress get_avatar filter to match logins
- Modify category listing API response
- ‘the_content’ Filter delivers empty string with lengh (608)
- Output dynamic_sidebar_params in wp_head
- How to sort posts according to meta value?
- Change shortcode output (filter?)
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- How to replace all images in all posts and pages with a different size?
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Updating User Profile on Registration
- remove_filter excerpt_more from a plugin class
- ACF Load Field Groups Programmatically [closed]
- Why does using excerpt_more filter change link location?
- How to elect position of new item output in a dropdown when using add_filter
- Query Multiple Filters, one with Meta
- How to remove a filter that is an object method?
- Filter a custom post type by custom field in admin