How to display only the first 2 words of a post title
-
Hi,
Learning WP and eventually want to build a site. I want to display only the first 2 words of a post title to the user but full title needs to be in the source for SEO. For example, if I make a recipe website and one of my recipes is “Vegetarian Burger – beans or tofu or veggies” but on archive pages or custom pages using a query loop, I only want to display “Vegetarian Burger” and not the entire title.
How would this be achieved? I tried ChatGPT and it gave some php code and instructed me to paste that in the functions.php file. I read somewhere on this forum that Twenty Twenty Four theme doesn’t use functions.php. So I have no idea how to go about achieving this. Building the site with purely 2024 blocks so the title is H1 class=”wp-block-post-title
There have been some examples of this but these are quite old posts on various websites like stachoverflow etc. Not sure if any new solution is there. I am not a developer so I am not sure who to go about it.
Thanks.
- The topic ‘How to display only the first 2 words of a post title’ is closed to new replies.