Solved

WordPress Shortcode Calling External Script

Posted on 2014-07-27
6
113 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 61

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 108

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 61

Expert Comment

by:gheist
ID: 40223898
0
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.

 
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 108

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

Title # Comments Views Activity
Form with Modals 16 43
unset shopping cart session 15 31
How to change pointer icon to hand icon on mouseover 2 19
Selecting SUM data from mysql table with PHP 4 6
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!
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 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

18 Experts available now in Live!

Get 1:1 Help Now