get wordpress custom fields outside the loop

June 12, 2009

Custom fields are very useful and are used on many WordPress blogs. But how to easily get custom fields values outside the loop? To display a custom field value outside the loop, simply use the following code. Don’t forget to replace Myfield on line 4 by the name of the custom field you want to display.   <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'MyField', true); ?>  Read More →

create wordpress page template to redirect to first child page

June 9, 2009

Many WordPress users uses parent pages and subpages to order the informations displayed on their blogs. Then how to be able to redirect to the first child page if the current page have children pages? You have to create a wordpress page template to redirect to first child page, Create a new file and paste the following code in it:   <?php /* Template Name: Redirect To First Child */ if (have_posts()) {   while (have_posts()) {     the_post();     $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");    ... [Read the full story]

hide specific wordpress sentence or text to Google robots

June 4, 2009

How to only hide a portion of text to Google, your navigation menu for example? Hiding a portion of text to Google is damn easy, but not everyone is aware of this method. Simply use the following html comments in your source files (or in WordPress editor, in html mode) to hide a specific sentence or text to Google robots. This text will be indexed by Google... <!--googleoff: all--> ...but not that one! <!--googleon: all> These tags tells Google that the text embeded within them should not be indexed. Of course,... [Read the full story]

Get rid of auto media enclosures on WordPress

June 2, 2009

When you’re adding a multimedia file as such as a mp3 or flv file, WordPress automatically create a custom field named enclosure and add the media url to your rss feed. Great for podcasters, but unusefull for most bloggers. Let’s see how to get rid of it. Just paste the following lines of codes within your functions.php file, and then, say goodby to automatic enclosures. function delete_enclosure(){ return ''; } add_filter( 'get_enclosed', 'delete_enclosure' ); add_filter( 'rss_enclosure', 'delete_enclosure' ); add_filter(... [Read the full story]

Create invisible wordpress custom fields

June 2, 2009

Many plugins use custom fields to store data about individual posts. When a plugin adds a custom fields, its key and value (or name and value) are listed in the Custom Fields meta box. For instance, a syntax hilighting plugin may set a custom field syntax_enabled on posts that use the syntax highlighting CSS. Often the user doesn’t need to see this information and it can leed to needless confusion. Unless the user needs to edit these custm field values there’s really no need to have them listed here. How to Hide... [Read the full story]