• 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)
  • 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

    Thread Starter CreativeWP

    (@creativewp)

    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?

    No, ‘avada_after_main_container’ is a theme specific function.

    Thread Starter CreativeWP

    (@creativewp)

    Is a hook, ‘avada_after_main_container’

    Moderator bcworkz

    (@bcworkz)

    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

    (@creativewp)

    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

    (@bcworkz)

    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.