Forums

Shortcode - Limited to one per php file? (4 posts)

  1. neosin
    Member
    Posted 3 years ago #

    Just wondering why it seems you can only user one shortcode per php file for a plugin?

    Im using them to call functions and require several in one file as opposed to one file for each function/shortcode.

    any way around this?

  2. Otto
    Tech Ninja
    Posted 3 years ago #

    Err... what?

    I don't fully understand exactly what you mean here. It's perfectly possible to define several shortcodes in one PHP file.

  3. neosin
    Member
    Posted 3 years ago #

    oh?

    this doesnt work for me

    function show_index(){
    	echo 'Example 1';
    }
    add_shortcode('myshow', 'show_index');
    
    function show_text() {
    	echo 'Example 2';
    }
    add_shortcode('myshow', 'show_text');

    the problem is that in the content where I put [myshow show_index] it is always showing the output from function show_text instead...

  4. Otto
    Tech Ninja
    Posted 3 years ago #

    Err.. you can't do that. That's not defining several shortcodes, that's defining the same shortcode twice. The second one overrides the first one.

    You can only define any given shortcode once.

    I suggest you reread the Shortcode API documentation.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.