Tag Archives: Tips And Tricks

A few WordPress Tricks.

April 9, 2007 by aaron
Just a few little tips for WordPress: If you don’t want the titles of posts to have the » character before them for SEO purposes just use: < ?php echo trim(wp_title('&raquo;',false), '&raquo; ');?> I was sick of my index.php being used to display pages, so I added the following to the top of my index.php to force WordPress to use single.php for all pages: < ?php if(is_page()){ include(&#039;single.php&#039;); exit; } ?> I wanted to be able to use javascript in some of my pages so I added the following to my header.php: <?php if(is_page()){ $j = get_post_meta($post->ID, &#039;header&#039;, true); if($j != &#039;&#039;){ echo $j; } } ?> Now anytime I need special style or javascript code added for a particular page I just add a custom field with the name header.
Read More ⟶

Redirecting a large number of posts to their new WordPress permalinks.

April 25, 2007 by aaron
Add this to the VERY top of your theme’s 404 page. Change http://localhost/wordpress to your default wordpress folder. This just does posts and possibly pages that end in the id (with or without the trailing url) Categories etc will have to be done elsewhere or by hand. < ?php //Kinda obvious $rf = $_SERVER[&#039;REQUEST_URI&#039;]; $rf = explode(&#039;/&#039;,$rf); $last = count($rf); //Filter out regular 404 that arn&#039;t old urls if(is_numeric($rf[$last-1])){ $post_id = $rf[$last-1]; }elseif(is_numeric($rf[$last-2])){ $post_id = $rf[$last-2]; } // No sense loading WP if there isn&#039;t an id if ( $post_id ) { // Oh fine we will load wordpress define(&#039;WP_USE_THEMES&#039;, false); require(&#039;http://localhost/wordpress/wp-blog-header.php&#039;); $post = get_post($post_id); //Well hope it is the right post.
Read More ⟶

A few WordPress Tricks.

April 9, 2007 by aaron
Just a few little tips for WordPress: If you don’t want the titles of posts to have the » character before them for SEO purposes just use: < ?php echo trim(wp_title('&raquo;',false), '&raquo; ');?> I was sick of my index.php being used to display pages, so I added the following to the top of my index.php to force WordPress to use single.php for all pages: < ?php if(is_page()){ include(&#039;single.php&#039;); exit; } ?> I wanted to be able to use javascript in some of my pages so I added the following to my header.php: <?php if(is_page()){ $j = get_post_meta($post->ID, &#039;header&#039;, true); if($j != &#039;&#039;){ echo $j; } } ?> Now anytime I need special style or javascript code added for a particular page I just add a custom field with the name header.
Read More ⟶

Redirecting a large number of posts to their new WordPress permalinks.

April 25, 2007 by aaron
Add this to the VERY top of your theme’s 404 page. Change http://localhost/wordpress to your default wordpress folder. This just does posts and possibly pages that end in the id (with or without the trailing url) Categories etc will have to be done elsewhere or by hand. < ?php //Kinda obvious $rf = $_SERVER[&#039;REQUEST_URI&#039;]; $rf = explode(&#039;/&#039;,$rf); $last = count($rf); //Filter out regular 404 that arn&#039;t old urls if(is_numeric($rf[$last-1])){ $post_id = $rf[$last-1]; }elseif(is_numeric($rf[$last-2])){ $post_id = $rf[$last-2]; } // No sense loading WP if there isn&#039;t an id if ( $post_id ) { // Oh fine we will load wordpress define(&#039;WP_USE_THEMES&#039;, false); require(&#039;http://localhost/wordpress/wp-blog-header.php&#039;); $post = get_post($post_id); //Well hope it is the right post.
Read More ⟶