Skip Navigation

[Resolved] How do I add a custom link to a post?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 2 voices.

Last updated by haukeB 8 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#328979

Using Types, I have created a custom post type called "my-event". Each "my-event" post only has a title and a custom field for the event's url called "event-site-url". There are no post pages associated with the "my-event" CPT. Only the titles are meant to show up on a page with the event listings. I would like the custom field holding the url to be the link for the post title. I might be explaining this in a convoluted way but the end result should simply be a list of event titles and each event title should be clickable and link to the event's website, NOT to the post page, as is the default with wordpress post links.

So my question is, is it possible - using Types - to assign the url of the custom field holding the event's site url to the post title, effectively turning it into a link to the even't website?

I know that this is possible by coding this functionality into the loop but I am just starting out digging into the WordPress code and I'm not yet knowledgeable enough to do this in code so I am still limited to doing most things inside the GUI using functional plugins such as Types.

#328992

Thank you for contacting us here in the Support Forum

You can, as example ,display your Post Title within a View, with this short code:
[wpv-post-title]

Then, to make it a link-to a external Site, which URL you store in a Custom URL Field, you can do this:

<a href="<em><u>hidden link</u></em> field="url" output="raw"][/types]">[wpv-post-title]</a> 

(if you don't hold the http:// in the Custom Field, other wise, remove it from above code)

This should convert your Post Title to a link referring to the site (URL) you hold in your Custom Field

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#329002
screen3.jpg
screen2.jpg
screen1.jpg

Thank you for the quick reply. Unfortunately, this didn't resolve my problem (or maybe I am not applying the fix correctly).

I am using the "Grid Element" tool of the "Visual Composer" plugin to generate my post links (see screen1). Here, I can add visual elements and populate them with the data fields of my cpt. If you look at the screen1, you'll see that I added one "Post Title" element (displaying the title of the post) and one "Text Block" Element. In the "Text Block" element, I added the short code you provided (see screen2) but on the page, the short code is not converted. Instead, the link is displayed literally as [wpv-post-title] (see screen3).

On the page itself, I am using a grid that dynamically pulls all the "my-event" posts and displays them so adding them individually is not an option here.

#329012

Thanks for the Details

Please apologize, I did not recognize you only use Types, and provided you Views ShortCodes.

To do this in Types only (and assuming you created your CPT's with Types) you can not use a Title ShortCode.
What you could do, is create a Custom Field with Types that hold your Title.

Then you could do, in a Post, TextMode:

<a href="<em><u>hidden link</u></em> field="url" output="raw"][/types]">[types field="your-field-for-title"][/types]</a>

Or, you can create your own short code, where you get the current Post Title and return it with a short code to use it in Types.

But I am not sure this will work, as it would be a nested ShortCode in a HTML attribute and WordPress recently discontinued support for this kind of links.
We solve it with Views, where you can register such custom ShortCodes so to parse them earlier, but that's not possible with Types only.
https://make.wordpress.org/core/2015/07/23/changes-to-the-shortcode-api/

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#329017
screen6.jpg
screen5.jpg
screen4.jpg

That sounds promising but unfortunately it is still not working. I created a "event_title" custom field and added your code to the excerpt section of the post in TextMode (see screen4). However, on the page this does not show up. To test, I added simple text to another event post's content area and that does show up (see screen5 and screen6).

#329023

Thanks for the Details

Can you test this in a default Types Custom Post Type or WordPress Type without using your Builder?

If it does not work there as well, I would need to request temporary access (WP-Admin and FTP) to your site
- preferably to a test site where the problem has been replicated if possible -
in order to be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ Please can you add links to each screen in question?
This way I can fast locate the edit screens and work on them

Please could you provide me the additional Infos?

Thank you for your patience.

#329046

Thanks for the Details

I am confused.

You don't have a single Custom Field in Types > Custom Field.
You would need to register all those fields first.

Otherwise it wont work. My Code above is to use with Types Custom Fields, not WordPress Custom Fields 🙂

We don't provide user-support for WordPress Default Custom Field Usage, for this you would need to query the WordPress Forums.

Types Button is also missing from your Post Edit Screens, is that hidden with custom code, or unexpected?

Please can you try to disable all plugins, but Types, then activate theme Twenty Fourteen, and check again?

❌ IMPORTANT ❌
- assure a full backup of your website and database first
⌥ You can use a plugin for this if you like.
I often use the Duplicator plugin for this purpose.
See: http://wordpress.org/plugins/duplicator/

Please don't hesitate to inform me in case the issue persists
Though, I am sure it will work once the Fields are registered in types > custom fields.

DOC:
https://toolset.com/documentation/user-guides/using-custom-fields/
https://toolset.com/documentation/user-guides/displaying-wordpress-custom-fields/
https://toolset.com/documentation/customizing-sites-using-php/functions/

Thank you for your patience.

#329069

I did not know that that's how to create custom fields for Types CPTs. I thought checking the "custom_fields" option when creating a CPT with Types was sufficient. That information helped a lot and I am a step closer now. The title is being displayed!

hidden link

However, it is not being displayed as a link. The anchor tag is being stripped. To make sure that the shortcode isn't messing with the display, I removed it from the anchor tag like so:

<a href="">[types field="news-article-title"][/types]</a>

But the anchor tag is gone. Only the title itself is there. Could you take another look and see if you understand why it's still not working?

#329078

Could you please set the previous exchange to private? I was not aware it went back to public. I thought every reply after the first private one would also be private. I would rather the information in those screen shots not be public.

#329090

I edited the code in this Post:
wp-admin/post.php?post=6178&action=edit

The output is correct to see here:
ni-news-item/crop-life-magazine-irrigation-control-gets-ever-more-precise/

If your link gets stripped in other content that is eventually reformatting your Post Body (like in a Builder), that might be a issue of the 3rd Party Plugin.

Please acknowledge that this is a issue of WordPress and not Toolset.
I mentioned this earlier in the Thread:
https://make.wordpress.org/core/2015/07/23/changes-to-the-shortcode-api/

We worked around this WordPress limitation in Types, of course assuming a display of types Fields with a WordPress default display of the Post Content
(we can not fix other Plugins in case they have the mentioned issue)

In Views it's worked around by registering any eventual 3rd Party ShortCodes, or using default Toolset Code.
We had to refactor the entire parsing process of ShortCodes since WordPress changed the ShortCodes API.

Please let me know if you have further questions regarding the issue mentioned in this Thread

PS
I removed the previous screenshots.

Thank you for your patience.

#332531

I found another plugin - "Page Links To" - that converts the title of a post into a custom link that I can define so this issue is resolved for me.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.