Search code examples
wordpresspermalinks

Get permalink of a post in order to make a custom button


I'm using advanced post slider and inside of it I have echoed a new button like this

echo  '<a class="dugmeupostu" title="get_the_title($ID)" 
href="<?php get_permalink();?>">Kliknite ovde za detalje</a>';        

But it doesnt take me to the post, it makes url with localhost/nameofsite/"

The post slider by itself makes title of the post a link and it works. My button doesn't.

Any ideas? Thx


Solution

  • You are trying to execute PHP statements in a string, that is not going to work. Your code should look like this:

    echo  '<a class="dugmeupostu" title="' . get_the_title($ID) . '" href="' . get_permalink() . '">Kliknite ovde za detalje</a>';
    

    or even, nicer formatted using printf:

    printf('<a class="dugmeupostu" title="%s" href="%s">Kliknite ovde za detalje</a>', get_the_title($ID), get_permalink());