Solved

WordPress Shortcode Calling External Script

Posted on 2014-07-27
6
122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
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 110

Author Closing Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
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 …

691 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