?
Solved

WordPress Shortcode Calling External Script

Posted on 2014-07-27
6
Medium Priority
?
123 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 111

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
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
LVL 15

Assisted Solution

by:eemit
eemit earned 800 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 1200 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 111

Author Closing Comment

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

Featured Post

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 count occurrences of each item in an array.
Suggested Courses

762 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