Last active
September 27, 2019 06:43
-
-
Save Maurisss94/5e34803732ad0ab9fb02b66add590fa7 to your computer and use it in GitHub Desktop.
Replace small links inside the content Wordpress with the permalink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fix_links_content($content) | |
{ | |
if (is_single() && get_post_type() === 'post') { | |
$content = preg_replace_callback('(\/\?p=[0-9]*)', | |
'replace_query_string_url', $content); | |
} | |
return $content; | |
} | |
function replace_query_string_url($matches) | |
{ | |
$id = explode('=', $matches[0])[1]; | |
return get_permalink($id); | |
} | |
add_filter('the_content', 'fix_links_content'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment