Archived topic
Are GP hooks unavailable in the Content Element?
5 replies · Started by Rekindle on October 5, 2021
Hi,
I'm trying to use the 'generate_before_entry_title' hook on a page. I have a basic Content Element for that page to set the content width: https://www.evernote.com/l/ASFGTNf5XxRElYOFul103hkESXEWQy2N2OI
I have a code snippet that uses the action hook, like this: https://www.evernote.com/l/ASG_OTdO6CtD4KtAv5Hf7GeFJEldiq_PP4Y
But the 'Hello' string isn't showing up on the page. If I trash the content element, then it shows up. Is the 'generate_before_entry_title' unavailable if I use the content element?
Thanks.
Hi there,
That's not possible unfortunately.
The content template can only be used to replace the default appearance of the posts loop on the blog and archive pages.
Let me know if this helps :)
Hi Leo,
I'm trying to remove a suffix from my post title. Elvin gave me a way to do that yesterday: https://generatepress.com/forums/topic/changing-post-title-programmatically/#post-1952862
How can I do this without deleting the Content element altogether? I'd like to use that element to generate the content width.
Thanks.
Hi there,
If you're planning on adding this one on a Block element then we can just turn the code into a shortcode so you can place it using a shortcode block. :D
Instead of hooking it manually, remove the code and use this instead.
add_shortcode('sfwd_quiz_title',function(){
ob_start();
// Start your PHP below
if( get_post_type === 'sfwd-quiz' ) {
$title = get_the_title(get_the_ID());
$title_without_code = substr( $title, 0, strlen( $title ) - 6 );
echo '<h1 class="entry-title">'. $title_without_code .'</h1>';
}
// End your PHP above
return ob_get_clean();
});
You then place a shortcode block where you want the title to appear within the BLock Element. And place [sfwd_quiz_title] shortcode in it. :)
Thanks Elvin. That works. Is there a way to style the shortcode output using the Content block or do I have to do it using custom CSS?
Thanks Elvin. That works. Is there a way to style the shortcode output using the Content block or do I have to do it using custom CSS?
You can change the class on the shortcode and use that custom style to do some custom CSS.
Or you can remove the class completely and place it on a container block and style the shortcode through the container block. (the shortcode block should inherit container block styles)