Creating A Really Dynamic WordPress Page

Published on
16,385 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.
  • 2
LVL 70

Expert Comment

by:Jason C. Levine
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.
LVL 17

Author Comment

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.
LVL 18

Expert Comment


Voted Yes, above, for this article.
LVL 17

Author Comment


Featured Post

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month