Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: External Permalinks
  4. * Plugin URI: http://wordpress.stackexchange.com/q/64285/73
  5. * Description: Uses the value of post meta field <code>syndication_permalink</code> as permalink if available.
  6. * Version: 2012.11.13
  7. * Author: Thomas Scholz
  8. * Author URI: http://toscho.de
  9. * Licence: MIT
  10. * License URI: http://opensource.org/licenses/MIT
  11. */
  12.  
  13. add_filter( 'post_link', 'wpse_64285_external_permalink', 10, 2 );
  14.  
  15. /**
  16. * Parse post link and replace it with meta value.
  17. *
  18. * @wp-hook post_link
  19. * @param string $link
  20. * @param object $post
  21. * @return string
  22. */
  23. function wpse_64285_external_permalink( $link, $post )
  24. {
  25. $meta = get_post_meta( $post->ID, 'syndication_permalink', TRUE );
  26. $url = esc_url( filter_var( $meta, FILTER_VALIDATE_URL ) );
  27.  
  28. return $url ? $url : $link;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement