<?php echo substr(get_the_title(), 0,42) ;?>
Notice the echo and the get_the_title()
This will get you the result you’re looking for.
Here’s an alternative to consider:
I’ve always found character limits cause weird word breaks that users find confusing.
WordPress has a function called wp_trim_words
that you can use.
<?php echo wp_trim_words( get_the_title(), 5, '...' ); ?>
5 – the number of words you want to show
‘…’ – the trail after the last word shown (so you could have ‘- cont.d’ or ‘…read more’ or something)
Related Posts:
- Custom Post Type Archives by Year & Month?
- Get custom post type slug for an archive page
- Custom Post Type Settings page, choose page to display archive
- Adding a menu item for a Custom Post Archive
- Replacing the title in admin list table
- Adding custom post type archives to a WordPress menu
- Custom Post Type Template – Archive
- How do you create an archive for a custom post type from a plugin?
- Custom Post Type Archives by Date with Custom Permalink
- How to List All Custom Post Types Names (Not Posts)
- Change title in head on Archive page
- What are the advantages of using a custom post type archive?
- Page is defaulting to archive page and not designated template
- custom post type archive page url to point to Page permalink
- Custom Post Type archive as front page
- Custom Post Type Works but Still Shows “Page Not Found”
- I can’t set meta_key in my custom post type query
- Adding Sticky functionality to Custom Post Type Archives
- Adding custom post types to archive.php
- Archive page for taxonomy of custom post type
- archive-{$post_type}.php not loading. instead the default archive.php loads
- How to make an archive page displaying posts in a date range
- Categories and Tags not working!
- WordPress custom post type archive with description
- Display Next/Prev when looping Custom post-types archive?
- Archive page for custom post type not working
- Editable content on a Custom Archive page
- Second Custom Post Type Archive
- How can I filter by taxonomy on a custom post type’s page?
- An empty Custom Post Type Archive page returns 404 in WP 3.1
- the_title filter returning wrong post type
- CPT Archive with core Category
- Set up Custom-Post-Type Author Archive
- Custom post type title is set by other custom post type
- get the custom post type title/name
- Custom post types and tag archive pages/permalink structure issue
- Custom post type templating problem
- Displaying Page as Custom Post type landing Page
- WordPress post_where & posts_join not working only for custom post type
- Single post with a Custom Post Type returns 404, when archives of the CPT work correctly
- CPT archive admin menu label
- Custom post type archive page blank
- Creating a Custom Post Type
- Display post content with respect to its title?
- Custom Post Type slug same as page name
- Content Editable CPT Archive?
- Paginate_links in custom post type template
- How to hyperlink content from archive page with custom post-type
- How to set up Custom Post Type archive page as Front page
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- How to integrate single and archive templates for custom post type in any WordPress theme
- ACF for custom post type archive pages: which hook to use?
- Show categories of custom post type and not all posts
- CPT Archive pre_get_posts not working?
- Removed custom post type archive page shows blog page
- Plain links in single-class.php and archive-class.php not working
- Make Next and Previous on single-$posttype.php use the same order as archive-$posttype.php
- Pagination does not work on Custom Post Type archive while trying to get load more function working
- CPT archive page – show one post from each taxonomy term
- Create a Custom Path to Archive
- Specifying a template for custom post type pages
- How to set a ‘page’ as parent of a custom post type?
- Archive page of CPT’s custom Taxonomy
- Archive page for WordPress Custom Post Type doesn’t show pagination from paginate_links()
- 2 Custom Post Types In 1 Archive Page?
- Custom post type archive URLs with a single taxonomy
- Different number posts per page based on custom post type term id
- How to change URL for custom post type archive?
- Displaying all posts by category and showing content on click
- Custom post type author issues
- ACF Pro Accessing fields on a Custom Post Type
- Do not show child pages within a file page
- Tell wordpress to show a single page instead of an archive page
- Custom post pagination not working
- Custom post type post_type_link gives “page not found” on any other custom post type
- Highlight a Post on archive page if it has a new comment?
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- How do I make my archive page look like popular reviewing sites (e.g., Polygon and Gamespot) [closed]
- Rewriting archive page slug to be different than custom post type slug
- Site loads very slow for archive custom post type page
- Remove the “View” Link in Post edit Admin
- Custom Post Type Archive Links Not Working
- CPT archive as home page
- Have two (permalinks) urls for a same custom post type
- How to display the FAQ Archive page in my menu
- Why is this custom post type defaulting to archive.php?
- How can I set up the URL for a category archive for a custom post type?
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- Archive Page Pagination not working
- single-mySlug.php works: archive-mySlug.php does not. Custom Post Type
- Create a Page Templete to Display Table Of Content for Custom Taxonomies
- has_archive for default post type
- Pagination for Custom Post Type with Multiple Types
- Custom Post Type Archive Title Lowercase
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- Show custom post type on post category page doesn’t work / breaks navigation
- On archive.php show loop for child categories if they exist or posts if they don’t, on custom post type
- Pagination not working on custom post type archive
- Best practice to display a list/archive of Custom Posts in a Page Template
- Archive pagination – second page shows exactly the same posts