Warning: Creating default object from empty value in /home/cf9819/public_html/shibumi.net/wp-content/themes/dkret3/header.php on line 17

How To Get WordPress to Link to an External URL

This requires a little code hacking but it’s pretty simple. Open up: wp-includes/classes.php and find function: start_el

After the if else block that sets the value of the $css_class variable add the following code:


$url = get_page_link($page->ID);
$post_url = get_post_meta($page->ID, "url", true);
if ( $post_url ) {
    $url = $post_url;
}

and then remove get_page_link($page->ID) from the following line<a href="' get_page_link($page->ID) . '".... and replace it with $url: <a href="' . $url . '"

Now log in and edit the page or post you wish to specify a customized url for. Add a ‘Custom Field’ with key: ‘url‘ and a value of the full url (including http://) that you wish to send users to. The screenshot below shows the completed hack. NOTE: This will get wiped out next time you upgrade! I’ve also used the same logic to show/hide posts and pages from the menu systems.