Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mcnaden

    (@mcnaden)

    Hi I just found a similar issue to mine that you solved.

    https://wordpress.org/support/topic/how-to-remove-permalink-to-from-post-title-hover?replies=2

    I had some custom code written from an earlier version of your plugin so that if custom field (RPW_externalurl) was filled in with an external link it would replace both thumbnail and post-title links.

    <?php $exclude_ids[] = get_the_ID() ;
    							$ext_url=get_post_meta(get_the_ID(), 'RPW_externalurl', true);
    							$ext_url=!empty($ext_url) ? $ext_url : get_permalink();
    						 ?>

    Could you tell me where to insert this or similar into your functions.php?

    Thread Starter mcnaden

    (@mcnaden)

    I added the following to my child theme functions.php and it solved the issue universally with the added benefit that I did not need to alter your code!

    // Add function to replace post permalink with external link if exists
    add_filter('post_link','check_for_custom_url',10,3);
    function check_for_custom_url( $permalink, $post, $leavename ) {
            $custom = get_post_meta(get_the_ID(), 'RPW_externalurl', true);
            return ( $custom ) ? esc_url( $custom ) : $permalink;
    }

    My custom field name in the aboce code is RPW_externalurl

    Maybe that helps someone with the same issue.

    Plugin Author Ga Satrya

    (@satrya)

    Hi @mcnaden,
    Glad you found the answer of your question. It also gives me an idea to provide a special filter inside the plugin. 😀

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘shortcode hook to override internal links with an external one’ is closed to new replies.