Directly Link to External Pages in Wordpress

Directly Link to External Pages in Wordpress

The most common use case of our clients is the publication of "complete" blog posts.

A complete post then consists of a selection comment (intro) and a list of commented articles. See the following screenshot for an example:

 

 

The look and feel of these posts can be customized by using templates that are optimized for the template that is currently in use.

However, there is another use case that some of our clients have: Instead of working with complete blog posts as see in the example above, these clients have a "news overview" page, where each item is a blog post, but when a user clicks on an item they are directly redirected to the external page. The following screenshot shows an excerpt of such a page:

Each entry in this grid corresponds with a selection that consist of one single article.

How can such a solution be built?

Each blog post that is created using the Scope plugin has the original image of the target page automatically integrated as a featured image and further has the URL of the target page in a custom field ("curated_urls"). Due to the vast amount of custom development, plugins and themes, Scope can not give general advice on a generic approach to build such a landing page. Please see the next section for a simple solution.

Simple URL Filtering

The following example snippet (Source: https://wordpress.stackexchange.com/questions/64285/change-post-permalink-to-external-url-from-custom-field) can be pasted at the end of the functions.php file of the theme currently in use. It will then always rewrite the URL of all blog post that have the custom field "curated_urls" to the value of this field.

You can locate the file functions.php in the wp-includes directory of your Wordpress instance. You will need access to the directory and editing rights via a file manager or FTP.     

 

Two related Warnings: 

  1. A customization like this requires advanced Wordpress knowledge. It will work with the default settings, but success and stability heavily depend on your custom Wordpress Setup. Scope can not provide advanced support for your Wordpress instance. 

  2.  Also, after a bigger Wordpress update, you may notice that your links will no longer go out directly. This means that your changes have been overwritten, and you will need to repeat them. For now, we cannot change this. At some point in the future, we might be able to find a smarter solution for this. 

 

/** * Plugin Name: External Permalinks * Plugin URI: http://wordpress.stackexchange.com/q/64285/73 * Description: Uses the value of post meta field <code>syndication_permalink</code> as permalink if available. * Version: 2012.11.13 * Author: Fuxia Scholz * Author URI: https://fuxia.me * Licence: MIT * License URI: http://opensource.org/licenses/MIT */ add_filter( 'post_link', 'wpse_64285_external_permalink', 10, 2 ); /** * Parse post link and replace it with meta value. * * @wp-hook post_link * @param string $link * @param object $post * @return string */ function wpse_64285_external_permalink( $link, $post ) { $meta = get_post_meta( $post->ID, 'curated_urls', TRUE ); $url = esc_url( filter_var( $meta, FILTER_VALIDATE_URL ) ); return $url ? $url : $link; }

Further reading material: