Solved

WordPress Shortcode Calling External Script

Posted on 2014-07-27
6
110 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 15

Assisted Solution

by:eemit
eemit earned 200 total points
Comment Utility
>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
Comment Utility
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
Comment Utility
Thanks for your help! ~Ray
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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!
The purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

744 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

13 Experts available now in Live!

Get 1:1 Help Now