Tag Archives: Tips, Tricks & Hacks

Setting up Ubuntu Server as a Virtual Machine (in Virtualbox) and using Subversion (svn) for the first time to checkout Google Code using shared folders

[iframe src=”http://blip.tv/play/h61qgsXLEQA.html” width=”100%” height=”378″]

In this screencast I explore using Subversion (svn) to checkout Google Code using Ubuntu Server in a virtual machine (using VirtualBox). The purpose of this screencast was two-fold.

  • First, I wanted to setup a Linux environment to use on Windows 7 for actual Linux stuff. As part of this I had to setup shared folders to the host operating system from the guest.
  • Second, I wanted to use Subversion (svn) to checkout some code (for the first time, for me).

So, in this screencast we will be:

  • Setting up a Virtual Machine and installing Ubuntu Server (10.10)
  • Setting up the required dependencies to install VirtualBox Guest Additions
  • Setting up VirtualBox Guest Additions and setting up and using shared folders on the host system
  • Installing and using Subversion (svn) to checkout some Google Code
  • Taking a snapshot in VirtualBox of our successful setup

This has been put in Code & Development because I will soon be using the virtual environment to run a local LAMP server (for a later screencast).

Simple Google Adsense Code Insertion/Injection WordPress Plugin using Custom Fields/Meta

[iframe width=”100%” height=”349″ src=”http://www.youtube.com/embed/tKUq5TZFeCU”]

Today I was working on adding a Google AdSense Ad into a post on the site, and I couldn’t (easily) find a WordPress Plugin that would let me do that easily; so, as always, I wrote one.

[adsense metakey=”my-cool-adsense-ad”]

To use add the shortcode to your post. (Not here, because it would actually try and insert something, please see video on these steps.)

Put your adsense code (that you copy from Google Adsense) in a Custom Field and call it whatever you want (called adsense-ad-1 here). The shortcode will pull in the AdSense code from that Custom Field in the location you put the shortcode in your post.

Enjoy.

Simple Google AdSense Code Insertion Plugin [zip]

[php wraplines=”true”]
/*
Plugin Name: Simple Google Adsense Code Injector Shortcode
Plugin URI: https://devblog.aubreypwd.com/
Description: This easy shortcode will allow you to insert your adsense code easily into your posts. Just put your adsense code betweent <code>adsense /adsense</code>.
Version: 0.1
Author: Aubrey Island
Author Email: enethrie@gmail.com
Author URI: https://devblog.aubreypwd.com
*/

function adsense_hand_enji( $atts, $content = null ) {
global $post;
extract( shortcode_atts( array(
‘metakey’ => ”,
//’attr_2′ => ‘attribute 2 default’,
), $atts ) );

$code= get_post_meta($post->ID, $metakey, true);

return $code;

}

add_shortcode( ‘adsense’, ‘adsense_hand_enji’ );
[/php]

Change Sub Category to Main Category URL Structure (WordPress Remove Sub Category Hierarchy URL)

While working on Enjfi, I ran into an undesired feature. When browsing to a sub-category, in WordPress, I ended up with a URL structure like:

[sourcecode]

https://devblog.aubreypwd.com/category/sub-category

[/sourcecode]

Now, that usually works. But, with Enjifi, I may want to move sub-category under category-2, like:

[sourcecode]

http://enjifo.com/category-2/sub-category

[/sourcecode]

Now, all my links to /category/sub-category are not /category-2/sub-category, the undesired feature.

So, I found this, and I wrote a plugin for it (because it worked).

sub-cat-to-main-cat.zip

[php wraplines=”true”]
<?php

/*
Plugin Name: Change Sub Category to Main Category URL Structure (WordPress Remove Sub Category Hierarchy URL)
Plugin URI: https://devblog.aubreypwd.com/
Description: This plugin will tell your website to remap /category/category/subcategory to /category/subcategory
Version: 0.1
Author: Aubrey Island
Author Email: enethrie@gmail.com
Author URI: https://devblog.aubreypwd.com
*/

/* From: http://wordpress.stackexchange.com/questions/7807/changing-the-category-permalink-structure/7817#7817 */

add_filter( ‘category_link’, ‘wpse7807_category_link’, 10, 2 );
function wpse7807_category_link( $catlink, $category_id )
{
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();

if ( empty( $catlink ) ) {
$catlink = home_url(‘?cat=’ . $category_id);
} else {
$category = &get_category( $category_id );
$category_nicename = $category->slug;

$catlink = str_replace( ‘%category%’, $category_nicename, $catlink );
$catlink = home_url( user_trailingslashit( $catlink, ‘category’ ) );
}
return $catlink;
}

?>

[/php]

Allow HTML in your Category Descriptions in WordPress

So, while I was actually starting to move posts over to this lovely site, I noticed that when I saved a category’s description, certain HTML was being stripped.

For example (please no comments on quotes, this is HTML5!),

[html wraplines=”true”]
<a href=http://www.vim.org/ target=_blank>Vim</a> is an editor that I came across when looking for alternatives to, what I was currently using, <a href=http://notepad-plus-plus.org></a>Notepad++. I eventually started customizing it and trying to get it to work for me. At one point I even gave up, but came back to give it a try again.

It eventually lead to <a href=https://devblog.aubreypwd.com/category/vim/aubreys-gvim></a>Aubrey’s gVim, as well as <a href=/tag/vimtips>vimTips</a> and <a href=/tag/aubreygvimtips>Aubrey’s gVim Tips</a>.
[/html]

In this piece of code, inside a category description, though links were allowed, the class=it was not!

This plugin really came in handy!

[Allow HTML in Category Descriptions]