How often do you find yourself making a change to a post or a page, clicking “Update” then the “View Page” link? Why not just have another button by “Publish” and “Update” that says ” and View” so you can do it all at once? Just a suggestion, maybe I’ll get around to writing a plug-in just in time for someone else to have written a better one or they include it in the core…. 🙂
Author: Aaron Belchamber
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.
This is one of my all-time useful and favorite WordPress shortcodes ever. It’s so simple, just put the code below into your active theme’s function.php file and now you have a very flexible and powerful shortcode where you can embed external PHP — provided the PHP code is in a file on your own site, of course!
function insert_script($atts){ extract(shortcode_atts(array("path" => '',"vals"=>''), $atts)); ob_start(); include($_SERVER['DOCUMENT_ROOT'].$path); return ob_get_clean(); } add_shortcode('insert_script', 'insert_script');
Here’s an example of its use. If you aren’t familiar with PHP’s parsestr() function, please click here. It’s a handy way to take any regular query string of variables you’d find in a URL, like ?s=1&action=go and “parse” them out into variable/value matches like: $s=1, $action=”go”, and so on….
This way, you pass useful variables in a verbose way in your code — it’s pretty transparent so if the code you’re including isn’t cryptic and is easy to follow, then so will the use of this shortcode in your WordPress pages and posts!
Just put this shortcode in any of your pages or posts, or widgets if you’ve managed to turn on shortcodes in your widgets. If not, click here to see how easy that is.
[insert_script path='/includes/db/database-connection.php' vars="cmd=show_table"] //Will find the script at the web root includes folder, parse the variables in the query string "vars" with the PHP command "parsestr()" and execute the PHP
It comes in handy — to be able to use those dynamic and very useful shortcodes in more places. I’m sure the developers of WordPress have a reason to make developers have to put this extra line in the active theme’s function.php file, so here it is. Yes, it’s that simple!
add_filter('widget_text', 'do_shortcode');
<?php define('WP_DEBUG', true); ?>
When you’re in development mode, it’s useful to get errors in scripts as they occur. Just place this line anywhere in your functions.php file for your active child theme and you will start seeing debug feedback complete with script names and line numbers. You can just remove this line, or set “WP_DEBUG” to false if you want to shut off debugging or definitely before you go live!
Sometimes, you may not have access to your ad delivery network on your website, but the fact they are embedding ads in your pages without the rel=”nofollow” tag is costing your site in SEO. One thing you can do is insert this handy JQuery code in your page footer. All it does is wait for your page to load then it scans all your links for a match unique to the ad network and adds the “rel=’nofollow’ attribute in those matching
tags.
Simply replace “ad-deliverer/” below to whatever unique part of the path you can use to identify your ad network, such as “doubleclick”.
$(document).ready(){ $("a").each(function(){ href=$(this).attr("href"); if (href.indexOf("ad-deliverer/")>-1){ $(this).attr("rel","nofollow"); } }); });