0

I want to add image link on wordpress site which redirect the user to the another page of same url but with different prefix. for example page url is mydomain.com/post1234 when user click the image on this page it redirect the user to the url mydomain.com/md/post1234

The following code print the current page url on every post page on site but i want to add "md" prefix in the url

<a href="<?php
$Path=$_SERVER['REQUEST_URI'];
$URI='http://www.example.com'.$Path;
?>"><img src="<?php bloginfo('template_url'); ?>/images/sgxx.png">Click Here</a>

Pls suggest the correct code to do this.

  • Both of questions are related to permalinks structure. I don't want to change permalinks. I want to add image link on header of all pages which redirect the user of current page url but with prefix like current page url : example.com/post1234 redirect page url: example.com/md/post1234 – Harendra Singh Jul 14 '15 at 16:00
0

Based on this question about retrieving Wordpress post slug, you could put together a link like the following:

<a href="http://www.example.com/md/<?php global $post; echo $post->post_name; ?>">link text</a>

Whether that goes to a functioning page or not, I don't know. It seems like you may want to change rewrite rules in the functions but I'm not sure from what you've said.

By the way, you may want to read why links that only say 'Click here' are bad practice for SEO and accessibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.