Site logo

Archived topic

Homepage Titles Link to External URL

1 reply · Started by Lewis on October 8, 2018

Viewing posts 1–2 of 2

Hi, I'm creating a content/link aggregation site with GP and I'm using ACF (Advanced Custom Fields) to populate some data.

I'm having trouble with getting the Homepage/Archive page entry titles to link to an external URL that is provided via an ACF.

I am aware of the “Link” post format - I've tried it and it works, however, the blog posts will not have any content - therefore I'd prefer to use custom fields if possible?

Any ideas?

Thanks!

You would likely need to use the post_link filter provided by WP.

Something like...

add_filter( 'post_link, function( $permalink, $post ) {
    $custom_field = get_post_meta( $post->ID, '_your_custom_field_name', true );

    if ( $custom_field ) {
        $permalink = $custom_field;
    }

    return $permalink;
}, 10, 2 );
This archived topic is closed to new replies.