You can use “wp_trim_words” function for this case.
Exam: To display the first two words.
echo esc_html(wp_trim_words( get_the_title(), 2, ” ) );
Use this code within your H1 tag.
You can control the number of words you want to show in the title by changing the second parameter of the function “wp_trim_words” to know more about this function visit wordpress.org
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- Alter query on edit.php
- Permanently remove first image from posts
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- Include a Gutenberg Block in a PHP file
- New Plugin Review
- Create custom blocks for bootstrap
- Use template for posts with a particular category grandparent
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Styling images coming from another blog
- Exclude posts from homepage having a specified tag
- “before delete post” action fire when the post is updated?
- Automatically add custom CSS to new posts using a category template
- Register JS for block on frontend only
- Query all posts of a custom taxonomy term
- Retrieving Author ID in wp-admin area
- Displaying the last post on static homepage
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- Best practice for migration friendly images in posts/pages?
- 200 Rewrite blog post links
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- Fetch post block/field data as JSON with WordPress API
- Automatically create child pages and grandchild pages when saving a (parent) page
- Where to find documentation for CPT block template? (PHP)
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Second transition_post_status hook fired instead of the first
- How can I add extra word in permalink when someone click download button?
- Custom posts in different columns style
- 404 error when I acess the second page of post-type
- Which PHP page is the Default Posts Page
- retrieve post data and insert it in seperate static html page without WordPress
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Returning data instead of echoing/printing
- Counting Search results, and displaying the offset per page
- Function works everywhere, how to keep it to execute when creating a new post
- Copy taxonomy terms from one post to another programmatically
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- How to catch wordpress post ID when it’s published
- Passing the name of selected color from the custom component to `render_callback`
- Find Site ID From WP_Post
- Reading settings in the home page precisely home.php
- WordPress upload file size error even after raising php limits
- Displaying list of posts in category page
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- how to edit a specific post slug using a php code?
- How to pick “full/thumbnail” images in the loop?
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Saving a post ID to use in a form elsewhere on website
- Prevent post from being published and show error
- WordPress – Get Posts with Category data
- remove specificly the last tag in all posts
- Pagination at category doesnt work with same name of page
- Add posts to custom table in database instead of wp_posts
- How to show categories and date on posts
- Gutenberg block don’t save rich text content
- Is there a PHP function that will return the block ID generated by WordPress?
- Query on a repeater date (acf)
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Check the database for a postmeta field
- Send POST request to Flask app from functions.php file
- How to pull date/time in french format for wordpress post?
- Send Notification after post published was working but stopped after the last WP update
- How to display last whole post on the homepage
- How to insert text into post based on category – via single.php file
- WordPress Single Post Pagination Numbered and Navigational
- Let user select the number of posts shown per page jquery error
- Add wp posts to cutom masonry grid
- Generate random access token to a post page
- Displaying 3 Category Posts differently
- Only display notification on single post
- Get posts associated with media attachment
- ‘posts_per_page’ in costum page type
- Passed variable gets undefined variable error on insert on next page
- List of child pages fetch next results at link click
- Automatically create a loop for post ID
- Why does WP_Query show only the same post even with different categories and endwhile?
- Different image and background color depending on page type
- Query posts by custom fields (object post)
- How to modify this function to exclude also the post belonging to a specific category?
- Excerpt all post content Content Same Size without word cutting off
- Set post to draft if matching word is found in the post
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- WooCommerce: write featured image dimensions to custom fields in product’
- How to enable REST API on custom post type without Gutenberg?
- transition_post_status hook, works – but not if the post is new
- do_blocks not working with a custom block
- Display two previous posts on single.php
- Execute a PHP Function when a Block is used and access it’s attributes
- change the blog in the url if you go from a specific page wordpress
- How to edit templates created in the block editor in code / template files not updating
- Programmatically convert single classic block to individual blocks via PHP
- Add custom data attribute to every core Gutenberg Blocks
- Get generated block styles programmatically
- Custom gutenberg block refuses to load viewScript and I don’t know why
- How to get the post title inside a custom block in a loop? block.js