WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode Exec PHP
Top plug. UI/Settings took a while to understand. (3 posts)

4 stars
  1. square_eyes
    Member
    Posted 10 months ago #

    Love it, it works. I am now passing shortcode attributes through to PHP variables.

    It took me a while to figure it out. Perhaps the config page could have a small example and explanation. i.e. set attribute, set up variable array (with default values) in php code to receive the variable, and finally use the variable in a short php script.

    Anyway. Keep up the good work.

  2. johnh44
    Member
    Posted 10 months ago #

    @square_eyes, do you have a short example you could post? Would help a lot of us, I bet! :-)

  3. square_eyes
    Member
    Posted 10 months ago #

    OK well this plugin is quite powerful, so this may not suit all scenarios. However, I would add something like this to get people started...

    :::: Shortcode - Put this in your page/post ::::

    Shortcode Example 1. Defaults

    [myphpscriptnamehere] - Calls 'myphpscriptnamehere' as configured in Exec PHP. Any variables in the script will parse as defaults (set in the PHP script below).

    Shortcode Example 2. Two Attributes Parsed as Variables

    [myphpscriptnamehere name="John" location="Earth"] - Shortcode includes two example attributes which we will parse as variables.

    :::: Settings and PHP Code ::::

    WordPress Admin -> Tools -> Exec PHP -> Scroll down to Shortcodes. Add your PHP, name the script 'myphpscriptnamehere' from above and click Add. Remember to add your PHP code, without the <?php and ?> tags.

    Example PHP Script (Works with both above)

    extract(shortcode_atts(array('name' => 'No Name', //Notes: Listens for 'name' attribute, and adds 'No Name' as default.
    			     'location' => 'Somewhere', //Notes: Listens for 'location' attribute, and adds 'Somewhere' as default.
    ), $atts));
    
    echo ('Hello ').$name.(' from ').$location; //Notes: When run on a page load our little app spits out the defaults, or attributes, based on the shortcode you used.

    Output when page/post is loaded...

    Example 1.
    Hello No Name from Somewhere

    Example 2.
    Hello John from Earth

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.