Get a label of event_website_url
-
Hi there!
Function tribe_get_event_website_url($event) outputs the url to the site.
Tell me please what function will help me get a label (label-text)?
I hope for your help. Thanks
-
Hi @viktazon ,
Thank you for reaching out.
Kindly find the link below, which may be of interest to you.
Thanks for answer!
But tribe_get_event_website_link() and apply_filters( ‘tribe_get_event_website_link_label’, $label ) it is assumed that the $label variable is known.
How do I get the $label variable?Hi @viktazon ,
Thank you for your message.
Looking into the underlying code of the
tribe_get_event_website_link()
function in\wp-content\plugins\the-events-calendar\src\functions\template-tags\link.php
, by default, the website URL becomes the label of the link that’s retuned if none was supplied.The
tribe_get_event_website_link_label($label)
filter hook allows you to change the label to something else.Thank you.
We need exactly the $label that the user specified when creating the event. I understand that I can replace it with my own, but it is the user-defined one that is needed, because the label text may be different.
In link.php the incoming variable $label is used, its original value is needed.
I need to output the value of the $label variableHi @viktazon ,
Thank you for your message and the clarification.
Regrettably, we do not have a function that extracts the $label for your use case. I recommend doing a regular expression to extract it from the
tribe_get_event_website_link()
function instead. The snippet below could work for you.$uri = tribe_get_event_website_link();
$get_label = preg_split('/<a[^>]*">([^<]*)<\\/a>/', $uri, -1, PREG_SPLIT_DELIM_CAPTURE);
$label = $get_label[1];Thank you.
If I try this code in /tribe/events/v2/list/event.php I see that
tribe_get_event_website_link() outputs url instead of label… label= url, therefore, regular expression does not help… although the label exists and is displayed correctly on the event pageHi @viktazon ,
Thank you for your message.
To help me understand the situation better, could you please provide with the code that you have for the
/tribe/events/v2/list/event.php
file and the direct URL of the page in question?Hi @viktazon
I hope you’re doing well. I just wanted to touch base and check in with you. It’s been a little while since we’ve heard from you. I was just curious if you had the chance to try out the recommendation provided above.
Let me know if there’s anything I can assist you with.
Hello!
Sorry for the delay in responding.
File event.php – https://dropmefiles.com/LE0Iy
Unfortunately, it is impossible to provide a direct URL, since it is a localhost. All other plugin files are unchanged.Hi @viktazon ,
Thank you for your message and the information.
Since you are using the
tribe_get_event_website_link()
function in an archive page, you would want to attribute the event variable to it like so:<?php
$uri = tribe_get_event_website_link( $event );
$get_label = preg_split('/<a[^>]*">([^<]*)<\\/a>/', $uri, -1, PREG_SPLIT_DELIM_CAPTURE);
$label = $get_label[1];
echo '$uri='.htmlspecialchars($uri).'<br>';
echo '$label='.$label;
?>I’m sorry, but the code works exactly the same. I’ve tried it this way.
Block Event Website:
Label-text – Google
Link – https://google.com1:
$uri=<a target="_self" rel="external">https://google.com</a>
$label=https://google.com
2:
$uri=<a target="_self" rel="external">https://google.com</a>
$label=https://google.com- This reply was modified 3 months, 1 week ago by viktazon.
Hi @viktazon ,
Thank you for your message and the information.
Are you saying you’re creating or editing events using Gutenberg block editor and have enabled Activate Block Editor for Events in Events -> Settings -> General (tab) -> Editing (section)?
Hello!
Yes, that’s right.
Everything is displayed correctly on the page of one event. I would like to display this button (link) on the event list (for each event from the list).Thank you for the confirmation, @viktazon . Let me check with the team about this, as when using the block editor, it will not be using the
tribe_get_event_website_link()
function to retrieve the website URL in the event single view.Hi @viktazon ,
As it turns out, when using the block editor, the label becomes embedded in the post’s (or event’s) content like so:
<!-- wp:tribe/event-website {"urlLabel":"the-website-url-label"} /-->
This means, we’ll have to discard the previous solution that I’ve shared and instead make use of the
get_the_content()
function of WordPress. Essentially, you’ll want to do a regex of what’s returned by theget_the_content( $event )
function to get the label that was inputted for the website URL block.I hope that makes sense.
- You must be logged in to reply to this topic.