WordPress.org

Ready to get started?Download WordPress

Forums

Execute shortcodes in post (2 posts)

  1. Noisie
    Member
    Posted 1 year ago #

    I am trying to execute a action like a dynamic sidebar connected to a shortcode in a post. What I am try'ing the archieve is a dynamic sidebar or hardcoded something like a googlemaps or mailchimp signup widget in a shortcode function. I want the code to display in the middle of the post or any other place I call it.

    I am experimenting with this code:
    function test_function() {
    return "<p>Here comes the output</p>";
    }
    function register_shortcodes(){
    add_shortcode('test', 'test_function');
    }
    add_action( 'init', 'register_shortcodes');

    When I dont use return the shortcode always execute in the top of the post. When I use the return function I can execute it on the place were I want it but it wont accept PHP code. The problem I have is it is nessecary to use php code to call a dynamic sidebar for example in the function document so I can fill it with a plugin or smt.

    Anyone can help me with a good article or tips?

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    execute a action like a dynamic sidebar connected to a shortcode

    tricky, because the 'dynamic_sidebar()' function always prints the result;

    you will need to work with output buffering; http://www.php.net/manual/en/book.outcontrol.php

    related plugins as possible sources for code snippets:
    http://wordpress.org/extend/plugins/widgets-on-pages/
    http://wordpress.org/extend/plugins/widget-or-sidebar-per-shortcode/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.