Hope you guys like this video. It's super easy to create a functions file for your block theme of choice. You can add any function into this file as you would in a classic theme. Looking forward to any questions that you might have. Have fun :-)
Hi Paul, I am new to Wordpress and designing my own site. I am not a developer. My requirement is for only the first 2 words of the post title to be shown whenever posts are fetched via a query builder. So when I use a query loop and it fetches the posts, only the first 2 words of the post title should be shown. Can you pls guide me on this? Thanks.
Hey @Whatreally123. Thanks for your message and welcome to WordPress. For your question, I am not sure how to go about doing that, as I assume you are using Greenshift query builder, is that correct? If so, then I put this into ChatGPT and it came out with this method. I have not tested this myself, so unsure if it will work. If it does not, I recommend to reach out to Greenshift support or post it up on the Greenshift Facebook group page. Here is the ChatGPT response: In Greenshift's block-based query loop, you can achieve showing only the first two words of a post title using custom code via a shortcode or custom block. Method: Using a Shortcode #### Add the following code to your theme’s functions.php file: #### function gs_first_two_words_title() { $title = get_the_title(); $words = explode(' ', $title); $first_two_words = array_slice($words, 0, 2); return implode(' ', $first_two_words); } add_shortcode('first_two_words', 'gs_first_two_words_title'); #### Use the Shortcode in the Query Loop Block #### In the Greenshift query loop builder, where you would normally insert the post title block, instead, insert a shortcode block and add [first_two_words]. This may or may not display only the first two words of the post title. Let me know how it goes and if it works.
Hope you guys like this video. It's super easy to create a functions file for your block theme of choice. You can add any function into this file as you would in a classic theme. Looking forward to any questions that you might have. Have fun :-)
Hi Paul,
I am new to Wordpress and designing my own site. I am not a developer. My requirement is for only the first 2 words of the post title to be shown whenever posts are fetched via a query builder. So when I use a query loop and it fetches the posts, only the first 2 words of the post title should be shown. Can you pls guide me on this?
Thanks.
Hey @Whatreally123. Thanks for your message and welcome to WordPress. For your question, I am not sure how to go about doing that, as I assume you are using Greenshift query builder, is that correct? If so, then I put this into ChatGPT and it came out with this method. I have not tested this myself, so unsure if it will work. If it does not, I recommend to reach out to Greenshift support or post it up on the Greenshift Facebook group page.
Here is the ChatGPT response:
In Greenshift's block-based query loop, you can achieve showing only the first two words of a post title using custom code via a shortcode or custom block.
Method: Using a Shortcode
#### Add the following code to your theme’s functions.php file: ####
function gs_first_two_words_title() {
$title = get_the_title();
$words = explode(' ', $title);
$first_two_words = array_slice($words, 0, 2);
return implode(' ', $first_two_words);
}
add_shortcode('first_two_words', 'gs_first_two_words_title');
#### Use the Shortcode in the Query Loop Block ####
In the Greenshift query loop builder, where you would normally insert the post title block, instead, insert a shortcode block and add [first_two_words]. This may or may not display only the first two words of the post title.
Let me know how it goes and if it works.