Solved

WordPress Shortcode Calling External Script

Posted on 2014-07-27
6
114 Views
Last Modified: 2015-10-29
Colleagues: This is for my own learning process, so I'm not interested in pre-manufactured countdown timers.  It's my intent to deliberately reinvent this particular wheel so that I learn the process.

I'm looking for some guidance on how to write and install a WordPress Shortcode that produces a countdown timer.  I've made some progress, for example, I expect the shortcode will look something like this:

[countdown]September 15, 2015[/countdown]

The design I'm contemplating would use jQuery/AJAX to repeatedly load() the output of a PHP script into a <div> that would be generated by the shortcode.  I'm pretty comfortable that I have the PHP script right and the jQuery right.  Where I need some help is the installation of the shortcode and the PHP script.

As I understand it, the countdown_timer() function will go into the functions.php file of my child theme.  And in the same file, following the function definition, I would put something like this:

add_shortcode('countdown', 'countdown_timer');

Since the PHP script is a separate program, not part of Wordpress, what is the right way to package it for distribution?  And where in the directory structure should I put it?

Thanks, ~Ray
0
Comment
Question by:Ray Paseur
6 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 40223481
Client-side javascript countdown would use 0 resources on your server. At least that was common practive 15 yeaars or so ago.
0
 
LVL 109

Author Comment

by:Ray Paseur
ID: 40223850
Yes, I understand that and I've used client-side countdowns when all I needed was time-sensitivity.  I'm working on a different server-based design for a variety of reasons.  Do you know how to package the PHP script for distribution?
0
 
LVL 62

Expert Comment

by:gheist
ID: 40223898
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 15

Assisted Solution

by:eemit
eemit earned 200 total points
ID: 40224022
>how to write and install a WordPress Shortcode?
>what is the right way to package it for distribution?
You must create a WordPress Plugin.
1
 
LVL 18

Accepted Solution

by:
Hube02 earned 300 total points
ID: 40275159
As @eemit has said, the best way to create a package for distribution and use in WordPress is to create a WordPress plugin. As you're looking for pointers, the best relevant information about the things you're describing can be found in the Codex:

Plugins: http://codex.wordpress.org/Writing_a_Plugin
Shortcodes: http://codex.wordpress.org/Shortcode_API
Ajax: http://codex.wordpress.org/AJAX_in_Plugins

However, you don't need to use a plugin if you're just creating this for the site or as part of a theme/child theme.  In your child theme create a folder named "inc" or "include" if it does not already exist. Create your php script file in this folder and then in your functions.php file for the child theme include the scripts with a standard php "include" statement.

Even doing it as part of a theme you should still check out the codex page for Ajax in Plugins. That page has the most useful information about doing AJAX in WordPress.
1
 
LVL 109

Author Closing Comment

by:Ray Paseur
ID: 41144260
Thanks for your help! ~Ray
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now