A few Wordpress Tricks.

Posted on Friday the 9th of March, 2007 at 1:56 pm in WordPress

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:

  1. <?php
  2. if(is_page()){
  3. include('single.php');
  4. exit;
  5. }
  6. ?>

I wanted to be able to use javascript in some of my pages so I added the following to my header.php:

  1. <?php
  2. if(is_page()){
  3. $j = get_post_meta($post->ID, 'header', true);
  4. if($j != ''){
  5. echo $j;
  6. }
  7. }
  8. ?>
  9. Use the following to copy and paste the code.

Now anytime I need special style or javascript code added for a particular page I just add a custom field with the name header.

Have you ever tried to validate your Wordpress site to use with Google Webmaster Tools? It can be a pain depending on the way your permalinks are, and even if those don’t cause a problem when Google tries to go to a random URL if the header isn’t 404 then it fails. Normally I just picked an off-time and renamed the htaccess file to the same as the validation file, validated and then changed it back. Well not anymore. Just add the following to your theme’s 404.php page and you should be all set. This will allow it to work even if Google doesn’t check it for an hour or ten.
Obviously you are going to change the whole google23423423423423.html part to the filename Google gives you.

  1. <?php if(strpos($_SERVER['REQUEST_URI'],'google234234234234.html') == false){
  2. header("HTTP/1.1 404 Not Found");
  3. }else{
  4. header("HTTP/1.1 200 OK");
  5. }
  6. ?>

Related posts

  1. James posted the following on March 12, 2007 at 3:09 pm.

    Just to let you know the first tip shows the charecter raquo not the word.

    Reply to James
  2. Aaron posted the following on March 16, 2007 at 8:51 pm.

    Thank you, it has been fixed.

    Reply to Aaron
  3. John posted the following on March 17, 2007 at 10:47 pm.

    What would happen if you added the Javascript header trick to a post?

    Reply to John
  4. uwiuw posted the following on March 11, 2008 at 6:15 am.

    wow, a great tips-n-trick….may i re-write and translate this post into my bahasa indonesia language in my blog ?

    Reply to uwiuw
  5. Aaron posted the following on March 11, 2008 at 10:44 am.

    You may, as long as you give credit to the original source and include a link to this page.

    Reply to Aaron
  6. uwiuw posted the following on March 12, 2008 at 12:13 am.

    absolutly, i will put credit on you :-D. thank you very much

    Reply to uwiuw

Leave a reply

:) :D :( :o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: ;) :!: :?: :idea: :arrow: :| :mrgreen: