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:
- Prevent post from being published and show error
- Want to unrestrict plugin block
- Wp Query : Order by distance lat,lon
- WordPress – Get Posts with Category data
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- remove specificly the last tag in all posts
- Pagination in single.php
- Pagination at category doesnt work with same name of page
- Add posts to custom table in database instead of wp_posts
- Additional file upload in Gutenberg page options/featured image
- Add Block Before Entry Title Using PHP
- get value from get_post_meta then reuse it in another get_post_meta
- Edit and delete permissions pages and posts
- understand what code is doing when prepending /blog
- How to show categories and date on posts
- Advanced Query posts
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- My worpress search page is showing no results
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- WordPress Post Block Element not properly parsed with the_content filter
- duplicate posts with ajax load more wordpress
- Filter wordpress posts without searching the keywords in the post content
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Gutenberg Blocks and get_option() for styling
- Build A Custom SQL Query for WordPress Search
- How to extend SelectControl with data from my theme
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Post form – AJAX won’t upload featured image – Plugin development
- How to Send Pingbacks for all Posts in WordPress?
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- WordPress sorting posts by date and title using a dropdown
- Gutenberg block don’t save rich text content
- Add Custom Post Type on the Fly or create an array
- Posts sortable column not sorting properly for custom field numbers
- WordPress article with 50 000 words loading slow – 100% cpu
- link to page_for_posts
- Display post of specific category on page
- HOW TO Insert Existing PHP Code to WOrdPress
- Query posts by custom fields (object post)
- How to modify this function to exclude also the post belonging to a specific category?
- How to customize posts in WordPress by using HTML and CSS?
- How to display the date under the post title?
- foreach all the post
- How to list all the posts in a personalized page? WordPress
- Excerpt all post content Content Same Size without word cutting off
- How to create a loop that will display one post and stop?
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Set post to draft if matching word is found in the post
- Disable single posts, but keep archive
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- Add default block css when the block has been added with php?
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin
- How to add different menu items on different menus?
- How to enable REST API on custom post type without Gutenberg?
- transition_post_status hook, works – but not if the post is new
- Replace block content with an array
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Include a static block inside of a dynamic block
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- Bulk data save in custom table
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- How to change post date and post time in WordPress automatically with a function
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- How to get ACF field to show up on all posts on front end?
- Global update of records after import WP All Import Pro
- Adding features to Gutenberg without theme.json
- Registering a custom block style
- Display posts based on the selected category when no subcategory is chosen
- Get column block count using PHP method render_block
- do_blocks not working with a custom block
- ACF block gutenberg aligncenter don’t work
- Display two previous posts on single.php
- (plesk)After adding 1000 youtube url to my 1000 different wordpress article, my all websites doesnt show yt url as embed
- 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 make posts_like_dislike reference current post when iterating?
- 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
- Category Attachment Pagination 404 Error on 2nd Page
- Add custom data attribute to every core Gutenberg Blocks
- Embed dynamic media query in a Gutenberg block
- Warning: Undefined variable $post_id
- Get generated block styles programmatically
- Custom gutenberg block refuses to load viewScript and I don’t know why
- When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?
- Issues applying JSON body filters in EU F&T Portal SEARCH API with WordPress integration
- Prevent render in editor via PHP
- How to get the post title inside a custom block in a loop? block.js
- How to get the content of a dynamic block in PHP
- Set custom post type to load custom block pattern by default