Community Pick: Many members of our community have endorsed this article.
Editor's Choice: This article has been selected by our editors as an exceptional contribution.

Creating A Really Dynamic WordPress Page

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a Visual Editor or HTML Editor.  These editors allow you to upload and insert images, videos, audio, as well as other multi-media. Absolutely great for creating simple text and media layouts.

What happens though, when you need more dynamic interaction than that which simple html could provide?  What happens if you want a page that will change based on inputs or calculations?  What do you do then?

Well, there are two choices.  One would be to install one of WordPress' great plugins, called Exec-PHP.  Exec-PHP allows you to stick code directly into your post or page and it will interpret the code correctly for execution.  There are several disadvantages to using this though.

1. You cannot use the Visual Editor

Exec-PHP can only operate correctly using the HTML Editor.  In order to use it, you must disable the Visual Editor.

2. Neither the Visual Editor nor the HTML Editor provide search functions

Writing code generally necessitates the ability to go back and debug coding.  A search feature is sorely lacking to help with this.

3. Debugging Code is difficult

The HTML editor was designed for HTML, not PHP.  If you write really complicated coding it could become very difficult to debug.
The other alternative is to use the wonderful ability of WordPress to be able to intercept content and modify it by simply placing a shortcode on a page.

In its most basic form, a shortcode is nothing more than a word surrounded by brackets (eg. [example]).  In the most complex form, a shortcode could contain start and end tags, attributes and content.  See WordPress' Shortcode API for a more detailed description.

Utilizing the shortcode, you can tie into custom PHP like so through your theme's function.php file:

                      // using the same [example] shortcode
                      function custom_shortcode_handler( $atts, $content=null, $code="" ) {
                         extract( shortcode_atts( array(
                            'attr_1' => 'attribute 1 default',
                            'attr_2' => 'attribute 2 default',
                            // ...etc
                            ), $atts ) );
                            $html = <set up your page html here using PHP>
                            return $html;
                      add_shortcode( 'example', 'custom_shortcode_handler' );

Open in new window

See for an example of using this code to produce a very simple form with form submit.

Using the shortcode opens up a world of possibilities for website development, with only your imagination as the limit.

Comments (4)

Jason C. LevineDon't talk to me.

Nice article.  I think it could benefit from a more concrete example of why you would need to do this instead of working inside the WP framework, though.


Thanks jason1178, I appreciate your kind remark.

The reason I wrote this article was to point out that not only is WordPress set up so that a novice can begin to put together a nice website using just the Visual Editor and/or the HTML editor and any of WordPress' multitude of themes and plugins, but it is also flexible enough to allow a more advanced developer to create complex dynamic web pages and still provide the ability to work in any theme.

Complex dynamic pages (such as those that rely heavily on database interaction, etc.) are very cumbersome to produce using the Visual Editor or HTML editor.  There remains two basic options after that, 1. Create your own custom theme and just include the coding in your templates (which would mean that you would be stuck with your theme), or 2. use shortcodes that run off the loop and can be integrated into just about any theme.

For marketability and overall usefulness, I opt for option 2.


Voted Yes, above, for this article.



Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.