Site logo

Archived topic

Add shortcode

1 reply · Started by Jose on March 31, 2021

Viewing posts 1–2 of 2

Hi,

I want to add a bit of html code using a shortcode.

I am trying the hooks on Elements, but I don't want to specify a display rule, I just want to add the shortcode myself directly in the page to just some blog posts.

What's the best way for doing that?

Hi Jose,

Not sure if I fully understand.

Are you wondering how to create a shortcode?

If so this is the general format:

add_shortcode( 'my_shortcode', function() {
    ob_start();
    // Start your PHP below
  
    YOUR HTML CONTENT HERE
  
    // End your PHP above
    return ob_get_clean();
} );

See lots of examples in our forum search:
https://generatepress.com/forums/search/add_shortcode/

This archived topic is closed to new replies.