Search:

Categories



List all active plugins

Lists all active plugins in wordpress, may be handy if you run a few sites

function wp_list_active_site_plugins() {
    $the_plugs = get_option('active_plugins'); 
    foreach($the_plugs as $key => $value) {
        $string = explode('/',$value); // Folder name will be displayed
        echo $string[0] ."\n";
    }
}

wp_list_active_site_plugins();
Share

WordPress old post warning

<?php
// Put inside Post Loop

$time_defined_as_old = 60*60*24*365; // A Year

if((date(‘U’)-get_the_time(‘U’)) > $time_defined_as_old) {
echo ‘<div><strong>Notice</strong><br />This article is published more than one year ago.</div>’;
}

?>

Share

Random video wordpress shortcode

This is an example of a wordpress shortcode that would display a random video, not very technical as the video embed is hard coded in but nice and basic

<?php
function md_random_video() {
	$videos = array(
		'Video Embed Code Goes Here',
		'Another Video Embed Code Goes Here',
		'So on',
		'So forth'
	);
	$rand_vid = array_rand( $videos );

	echo $videos[$rand_vid];
}

//Shortcode for WordPress only!
add_shortcode( 'randvid', 'md_random_video' );
?>

 

Share

Add googlemap to post or page wordpress

// add to functions.php
//Google Maps Shortcode
function fn_googleMaps($atts, $content = null) {
extract(shortcode_atts(array(
“width” => ‘640’,
“height” => ‘480’,
“src” => ”
), $atts));
return ‘<iframe width=”‘.$width.'” height=”‘.$height.'” frameborder=”0″ scrolling=”no” marginheight=”0″ marginwidth=”0″ src=”‘.$src.'”></iframe>’;
}
add_shortcode(“googlemap”, “fn_googleMaps”);

// add to post/page
[googlemap width=”200″ height=”200″ src=”[url]”]

Share

Automatically link Twitter usernames in WordPress

/* Automatically link Twitter usernames in WordPress*/
function twtreplace($content) {
$twtreplace = preg_replace(‘/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/’,”$1<a href=\”http://twitter.com/$2\” target=\”_blank\” rel=\”nofollow\”>@$2</a>”,$content);
return $twtreplace;
}
add_filter(‘the_content’, ‘twtreplace’);   
add_filter(‘comment_text’, ‘twtreplace’);
Share

Delete the Hello Dolly plugin

This is part of a set of scripts that I was writing to setup WordPress the way I want.

This one deleted the Hello Dolly plugin, the script has to go in the root where wordpress was installed (in beside the config, htaccess files). This was tested on XAMPP on a Windows machine.

<?php
include “wp-load.php”;
require_once(‘wp-blog-header.php’);
require_once(‘.\wp-admin\includes\plugin.php’);
require_once(‘.\wp-admin/includes/file.php’);

if (file_exists(WP_PLUGIN_DIR . ‘/hello.php’))
{
delete_plugins(array(‘hello.php’));
echo “Hello Dolly deleted”;
}
?>

Share