Adding a function to wordpress theme to bypass/replace premalinks

Looking at Cssremix.com

when you hover over a item you can see the “Views” function I’m assuming they are using a plugin that links with the post views but when clicked the item redirects not to the post but to a website/site used

Related posts

Leave a Reply

1 comment

  1. This plugin gives you the post views. To filter a link you can hook into certain filters, such as post_link or the_permalink.

    Here are some docs:

    The usage would be something like this:

    add_action('post_link', 'do_custom_link');
    
    function do_custom_link($url, $post) {
      $external_url = get_post_meta($post->ID, 'external_url', true);
      if($external_url) {
        return $external_url;
      }
    
      return $url;
    }
    

    This would get the external url from a meta field stored with the post, called external_url. You would define that meta field using the custom fields UI when you create the post through the admin pages.