Hi kramer1711,
You could write a function that creates the url structure for you. Something like:
$url = get_site_url();
$tagBase = ( get_option( 'tag_base' ) ) ? get_option( 'tag_base' ) : 'tag';
foreach ( get_the_tags() as $tag ) {
$tagUrl = $url . "/" . $tagBase . "/" . $tag->term_id;
}
Then use that function to display your tags.
Hi dbough,
Thanks for reply. can you write more about it? I know just quite a bit about wp structure and have no knowledge how to use this code properly…
I assume your setup will recognize URLs formatted this way already?
Add this to your themes functions.php file. It could use some refactoring but it will get you started.
This will update the tag url anywhere that tags are displayed with ‘the_tags’:
function filter_tag_slug_to_id( $content )
{
$dom = new DOMDocument;
$dom->loadHTML( $content );
foreach ( $dom->getElementsByTagName('a') as $node) {
if( $node->hasAttribute( 'href' ) ) {
$url = $node->getAttribute( 'href' );
$tokens = explode( '/', $url );
$term = $tokens[sizeof($tokens)-2];
$tagId = get_term_by( 'name', $term, 'post_tag' )->term_id;
array_pop( $tokens );
array_pop( $tokens );
$newUrl = implode( '/', $tokens ) . "/" . $tagId;
$content = str_replace( $url, $newUrl, $content );
}
}
return $content;
}
add_filter ( 'the_tags', 'filter_tag_slug_to_id' );