• Resolved Zippo

    (@sarrelibre)


    I have a custom field called “link” which is filled with an url to an external website. I like to fill in this URL in a href-value of an a-element

    It should look like this

    <a href="https://mycustomfield.com">Click</a>

    But it looks like this:

    <a href="&lt;div class=&quot;lcp-customfield&quot;&gt;https://mycustomfield&lt;/div&gt;">Click</a>

    My template goes like this:

     $lcp_display_output .= "<a href='$link'>";
     $lcp_display_output .= "Click";
     $lcp_display_output .= '</a>';
    

    How can I get rid of the tags around my custom field in order to get a functioning link on my web page?

    Thanks in advance for your help!

    Zippo

    • This topic was modified 1 year, 9 months ago by Zippo.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor zymeth25

    (@zymeth25)

    You need to remove custom field display options from your shortcode and get the custom field’s value in your template using the get_post_meta function.

    Example:

    $link = get_post_meta($post, 'link', true);
    $lcp_display_output .= "<a href='$link'>";
    $lcp_display_output .= "Click";
    $lcp_display_output .= '</a>';
    Thread Starter Zippo

    (@sarrelibre)

    Thanks a lot for your answer! But unfortunately this didn’t work.

    But I found another solution at the web which is working:

    $link = get_post_custom_values($key = 'link');
    $lcp_display_output .= "<a href='$link[0]'>";
    $lcp_display_output .= "Click";
    $lcp_display_output .= '</a>';
    Plugin Contributor zymeth25

    (@zymeth25)

    Sorry, I forgot the $post variable in the template is an object not an id. So it should be $link = get_post_meta($post->ID, 'link', true);

    Thread Starter Zippo

    (@sarrelibre)

    Thank you! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Strip tags from output’ is closed to new replies.