0

I have a page containing a post grid. Within the text of these posts I want to use a shortcode to display the title of the page containing this grid. So, when my page title is "test" I want to be able to display "test" within the content of my post text in the post grid. I made this simple shortcode

function page_title_sc( ){
   return get_the_title();
}
add_shortcode( 'paginatitel', 'page_title_sc' );

but this code displays the title of the post in my grid, not the title of the page containing this grid. Is there a way to change this shortcode so it can display the page title instead of the post title?

3
  • Please edit your question to show us more of the code in question. How are you creating your "post grid"?
    – Pat J
    Jan 19, 2021 at 16:38
  • I'm creating the post grid with the bakery builder Post Grid building block. Am I correct that I can only do this by custom coding? I suppose the post grid building block starts a new loop for the posts so get_the_title will display the title of the post? I'm using the Post grid block because I want to show random posts in a certain category. I can make some custom code to (1) get the ID's of the random posts (WP_Query), reset the post data (wp_reset_postdata() and then displaying the posts by ID (without stating a new loop). But is this the only way to do this?
    – marjoleins
    Jan 20, 2021 at 12:33
  • 1
    You will have to ask the plugin or theme developers / support any questions about how to use their product.
    – Pat J
    Jan 20, 2021 at 15:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.