Archived topic
do shortcode not working before entry title
2 replies · Started by rikdol on May 16, 2022
i'm using metaslider that produces a shortcode to display a slider.
using Elements > hooks
i've created a hook on generate_before_entry_title and checked shortcodes + php
also added a simple echo to see it show up.
<?php
add_action( 'generate_before_entry_title', function() {
do_shortcode('[metaslider id="212"]');
echo "kenobi";
} );
?>
also tried without the add_action:
<?php
do_shortcode('[metaslider id="212"]');
?>
But it won't show up, even with display rules set to 'homepage' or 'everywhere'
My problem was using a wrong hook it seems. after googling on different topic i came by : https://docs.generatepress.com/article/hooks-visual-guide/
Which helped me pick a different hook at the location i was trying to add it to.
solved.
Hi there,
if you use a Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Then:
1. Just add the shortcode: [metaslider id="212"] to the text area.
2. Check the Execute Shortcode option.
3. Set the Hook to where you require it*
4. Set the Display Rules > Location to where you need it eg. if you want the Home Page then the location is Front Page
* The hooks vary on what page you're viewing. For example the: generate_before_entry_title only exists on a Post not a static page. Instead try the generate_before_content hook.
See here for the common hooks: