Site logo

Archived topic

do shortcode not working before entry title

2 replies · Started by rikdol on May 16, 2022

Viewing posts 1–3 of 3

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'

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:

https://docs.generatepress.com/article/hooks-visual-guide/

This archived topic is closed to new replies.