• Resolved ducknet

    (@ducknet)


    Hi guys,

    I’m still fairly new to PHP but I’ve managed to make some nice shortcode for adding the post title in my posts. However, I now wanna add a hyperlinked image which comes up before the title which links to a local playlist file on my computer.

    Here’s my attempt which is clearly wrong;

    function myshortcode_title( ){
       $title = get_the_title();
       $url = ("<a href=\"file:///Guru/", '$post->ID', ".m3u\""><img
    src=\"http://ducknet.me/guru/play.png\"></a>");
       return $url.$title;
    }
    add_shortcode( 'page_title', 'myshortcode_title' );

    MY RETURN OUTPUT NEEDS TO BE:
    <a href="file:///Guru/(POST_ID).m3u"><img src="http://ducknet.me/guru/play.png"></a> (POST TITLE)

    In fact, I might move the closing tag after the post title but that should be the easy part. I tried using \” to include quotes within my PHP quotes, but I must be doing something wrong because my site breaks with the above code.

    What am I doing wrong??

    Thanks,
    Colin.

Viewing 1 replies (of 1 total)
  • Thread Starter ducknet

    (@ducknet)

    Haha.. I got it to work… For those who may struggle with this, use single quotes and then put your double quotes in normal, like this… As a separator, don’t use a comma, but a period!

    function myshortcode_title( ){
       $title = get_the_title();
       $id = get_the_ID();
       $url = ('<a href="file:///Guru/'.$id.'.m3u"><img
    src="http://ducknet.me/guru/play.png"></a> ');
       return $url.$title;
    }
    add_shortcode( 'page_title', 'myshortcode_title' );
Viewing 1 replies (of 1 total)

The topic ‘Adding a href image to my shortcode title??’ is closed to new replies.