0

I would like to know if anyone knows how I can get the call to a wordpress slug with a wordpress function. All this in order that everything is added automatically in the following way, EXAMPLE:

<link rel = "alternate" hreflang = "fr-BE" href = "https://www.moneytrans.eu/belgium/{{SLUG HERE}}" />

As you can see, I only need the function to take the slug of the page without including directories or anything like that.

Thanks for your support!

2
  • 1
    If you want to get the post slug of the current page you can use get_post_field('post_name'). If you want to get the whole page url you can use get_permalink() Oct 5, 2021 at 15:05
  • Hi @Buttered_Toast Will you have an example of how I can apply it? Ideally, at the end of the tag: <link rel = "alternate" hreflang = "fr-BE" href = "moneytrans.eu/belgium/[[SLUG HERE}}" /> In the variable {{SLUG_HERE}} I ​​recognize the function and bring me the data. Oct 5, 2021 at 16:22

1 Answer 1

1

Going by your link tag and the place you want the slug in, the code would be like this.

<link rel="alternate" hreflang="fr-BE" href="https://www.moneytrans.eu/belgium/<?= get_post_field('post_name'); ?>" />

You don't need to add all those spaces in attributes, for example, instead of rel = "alternate" do rel="alternate", and so on.

1

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.