Title: Inserting shortcode via add_action
Last modified: July 17, 2018

---

# Inserting shortcode via add_action

 *  [CreativeWP](https://wordpress.org/support/users/creativewp/)
 * (@creativewp)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/)
 * Hello everyone, I was trying to figure out how to add a shortcode via function.
   php I thought this would work, but it does not activates the shortcode there,
   what am I doing wrong?
 *     ```
       function show_post_slider_layout_before() {
       echo do_shortcode('[contact-form-7 id="12319" title="contactus"]');
       };
       add_action('avada_after_main_container', 'wpsline_action_footer');
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [HudsonValleyWebDesign](https://wordpress.org/support/users/jaycbrf/)
 * (@jaycbrf)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10502735)
 * Sorry, that theme is not supported in this forum. The custom functions may conflict
   with WordPress core functionality. Please visit the site where you purchased 
   the theme for support [https://themeforest.net/item/avada-responsive-multipurpose-theme/2833226/support](https://themeforest.net/item/avada-responsive-multipurpose-theme/2833226/support)
 *  Thread Starter [CreativeWP](https://wordpress.org/support/users/creativewp/)
 * (@creativewp)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10502974)
 * Ah, the theme is not important, I am using that theme however, but I am looking
   at the hooks. But this code could work, with any theme, no?
 *  [HudsonValleyWebDesign](https://wordpress.org/support/users/jaycbrf/)
 * (@jaycbrf)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10504998)
 * No, ‘avada_after_main_container’ is a theme specific function.
 *  Thread Starter [CreativeWP](https://wordpress.org/support/users/creativewp/)
 * (@creativewp)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10505583)
 * Is a hook, ‘avada_after_main_container’
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10506153)
 * Yes, a hook, not function. It’s still theme specific.
    Try `add_action('avada_after_main_container','
   show_post_slider_layout_before');` after your function declaration.
 * HVWD is correct, commercial theme support is not provided in these forums. If
   the above does not help, you will need to seek support through your theme vendor.
 *  Thread Starter [CreativeWP](https://wordpress.org/support/users/creativewp/)
 * (@creativewp)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10506546)
 * Thank you, I will try that. To tell you the truth, it is only curiosity to be
   able to do this, NOT a job, for this, or any other theme. But the theme is irrelevant
   to this code to me, it is the idea of been able to insert a shortcode via a hook
   in a theme via function.php
 * Thank you for your help,
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10508924)
 * That’s fine, why you are doing something does not matter, but if you use theme
   specific hooks and have issues with them where you need help, you will be sent
   to the theme specific support channel of whatever theme you are using. Generally
   speaking, for maximum compatibility, try to find a hook to accomplish what you
   want that is from WP core.
 * It’s not advisable to alter a theme’s functions.php file unless you wrote the
   theme. Your custom code should either go into a child theme or custom site specific
   plugin. Many commercial themes are framework based and take up the one available
   child theme position, which means the only safe place for your code is a plugin.
   That said, it seems that a lot of commercial child themes are never updated (
   a security concern in itself), so altering such themes might not otherwise be
   a problem. Keep a backup of your work just in case it does get updated.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Inserting shortcode via add_action’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/inserting-shortcode-via-add_action/#post-10508924)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
