Link post directly to external link

Hi there,

I have managed to link portfolio items directly to an external link (essentially changing the permalink) using some code that was plugged straight into the x-child theme’s function.php file, and then add a custom field using ‘x_custom_link’. The code used was:

add_filter( ‘post_type_link’, ‘x_remap_portfolio_to_page’, 10, 4);
function x_remap_portfolio_to_page($post_link, $post, $leavename, $sample) {

if ('x-portfolio' == $post->post_type) {
    $custom = get_post_custom($post->id);

    if (isset($custom['x_custom_link']) && $custom['x_custom_link'][0]!='')
        return $custom['x_custom_link'][0];
}

I want to do the same thing with posts. Do you know how I would change/add code to enable posts as well as portfolio items?

Thanks for your help!!!

Hi Brad,

It is a different case for blog post. The easiest way is to use a plugin. You might want to check this: http://www.wpbeginner.com/wp-tutorials/how-to-link-to-external-links-from-the-post-title-in-wordpress/

In case you want the code, the template responsible is : wp-content\themes\x\framework\views\integrity_content-post-header.php. Copy the template on the same folder on your child theme. Then feel free to edit the code. It is the href value.

Hope this helps.

Aha! Success! The plugin is great - thanks for the suggestion.

Thanks so much for your assistance :smile:

You’re always welcome!

Cheers.

How can I link a post from this page www.candyronnie.com/blog to an external site without using a plugin? I only want to link one post.

Thank you!

Hello @LucyKeile,

Thanks for updating this thread! What you want could only be done with a custom development. You will have to get use the Method 2 from this tutorial: http://www.wpbeginner.com/wp-tutorials/how-to-link-to-external-links-from-the-post-title-in-wordpress/

As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

Thank you for your understanding.