Creating A Really Dynamic WordPress Page

Published on
16,565 Points
5 Endorsements
Last Modified:
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 http://www.experts-exchange.com/Web_Development/Blogs/WordPress/Q_27254078.html 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.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free