Support » Plugin: Toolset Types - Custom Post Types, Custom Fields and Taxonomies » Adding target_blank and class to Types URL in PHP

  • Hi,
    I am building a download table in PHP, where the user adds the URL in a WP Types custom field in the backend, and the table containing the download link and other information renders at the frontend.
    I can do this successfully with the normal Types API. However, I wanted to add a target _blank to the link to open in a new tabl, and want to style the link to look like a button.
    When I followed this Topic:
    I could not combine it with php. it will always give me errors.

    i tried this code:
    echo "<a target='_blank' href="[types field="download-link" raw="true"][/types]"> Link Text </a>";
    but gave me this error:

    Parse error: syntax error, unexpected 'field' (T_STRING), expecting ']' in /home/coptic/public_html/text/wp-content/plugins/coptic-treasures-functions/functionality-plugin.php on line 130

    How to combine the WP Types url custom field with a target _blank and a class in php?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I tried to do a workaround but did not work too:

    – I created a url field (called it “download-link”,
    – pasted the download link in
    – then created another field, single line text and called it “dowdnload-carrier-field”
    – then put this code in:
    <a target='_blank' href="[types field="download-url" raw="true"][/types]">Download Link</a>

    – Then added this to the php template:
    <?php echo types_render_field( "download-carrier-field", array( ) ); ?>

    A link with the text “Download Link” appeared, but the link in it was:[types%20field=

    i tired the process without the raw="true" also, but did not work.

    Any suggestions, please?

    thanks a lot.

    Plugin Support Beda


    You need to use the Types API:

    Types Fields API

    It has a attribute for target.

    This can be used also in PHP.
    The example is on the above linked page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding target_blank and class to Types URL in PHP’ is closed to new replies.