Sample useful WordPress shortcodes – show Google ad snippet, user’s IP address, current time

Here are a few more useful WordPress shortcodes.  Simply copy the code and paste it into your active theme’s “function.php”.

You can call on shortcodes with the square brackets inside your post or pages:

Insert a Google ad snippet, horizonal 720 x 90 pixels:

[insert_script path='/library/vendors/google/ads/horiz-720x90.php']

Show computer’s IP address:

[[show_ip]] — produces:  [show_ip]


/* Allows insertion of external PHP scripts easily into pages, posts & widgets.
*
* "vars" is query string that will be parsed by script in a variety of ways,
* Most useful is parse_str()  where ?x=1&y=3 will parse into script as $x=1, $y=3
*/
function insert_script($atts){

extract(shortcode_atts(array("path" => '',"vars"=>''), $atts));
ob_start();
include($_SERVER['DOCUMENT_ROOT'].$path);
return ob_get_clean();
}

add_shortcode('insert_script', 'insert_script');

// Shows current Date and Time
function todays_date_time($atts){
return date("Y-m-d H:i:s");
}
add_shortcode('todays_date_time','todays_date_time');

// Shows computer's current IP address
function show_ip(){
return $_SERVER['REMOTE_ADDR'];
}
add_shortcode('show_ip','show_ip');

 

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *