Archived topic
Displaying custom blocks inside Tutor LMS pages/templates
15 replies · Started by _blank on June 23, 2022
Hello,
I would like to ask you for a help with adding a custom elements (blocks) inside Tutor LMS pages/templates.
For example: I would like to add a simple heading after the course enrolment button.
How would I go about doing that?
I played a bit with custom elements (Appearance -> Elements -> Add new -> Block), I set the location to "Course" and then on a sidebar I choosed "Element type -> Hook" , and for Hook name I choosed "Custom hook".
Then I tried to look up the tutor lms documentation and I found this: https://docs.themeum.com/tutor-lms/developers/hooks/
But honestly I don't know how to use this.
Any help would be much appreciated. Thank you.
Hi there,
then on a sidebar I choosed “Element type -> Hook” , and for Hook name I choosed “Custom hook”.
That's the correct method. From there, you would need to enter the name of the custom hook and it depends on where you are trying to insert the content.
This is something you will need to check with TutorLMS' support team.
I don't believe the page you've linked is what you need but their support team should be able to clarify.
So I wrote to Tutor LMS support and they responded with this:
"You can use this hook to add: https://docs.themeum.com/tutor-lms/developers/hooks/templates/#course-enroll-box-php"
However, I am not quite sure how to target this and what should I enter in "Custom hook" field.
Could you please help me with this?
Hi there,
1. Create your block element.
2. Set the Element Type to Hook.
2.1 in the hook list select Custom Hook.
2.2 in the Field paste in:
tutor_course/single/enroll_box/after_thumbnail
3. Set your Display Rules > Location to the Tutor Course Single ? - i am not sure what it will be called but look through the list of options.
Thank you David. I did exactly the same as you state above but it doesn't work.
As for a display rules, there is a location "Course". So I set that.
But when I did exactly this, it doesn't work. Would it help you if I give you a temporary access to my site?
Can you link me to the page where it should display ?
If i need a login or anything, then you can share those details in the Private Information field.
Sure David, here is the course page.
If you temporarily change the Hook to: before_header which is in the list of hooks. Does your block element content display? It should be above the site header
If it does, then we know the Display Rules are correct and the custom hook is bad
So I changed the hook to before_header and it does display on the frontend as it should.
So, the custom hook we try to locate is bad.
I noticed that after I add this hook tutor_course/single/enroll_box/after_thumbnail in GP Theme (custom hook), after I save it and reload the page, it loses those / (slashes), so therefore, it looks like this tutor_coursesingleenroll_boxafter_thumbnail
To be honest i have never seen hook method with / being used in this way before.
Can you check with Tutor on how they expect us to use it ?
Hello David,
so I wrote to Tutor LMS Support and I got this answer:
As he was referring to this hook tutor_course/single/enroll_box/after_thumbnail , you can use this, using this you can add your custom section.
Best Regards,
Which, I would say, doesn't help us in any way..question is what now?
Try adding this PHP Snippet to your site:
add_action('tutor_course/single/enroll_box/after_thumbnail', function(){
echo 'if i see this text then the hook is working';
});
Do you see the text appear on the page ?
I added the above PHP snippet and the text "if i see this text then the hook is working" is displaying on every page before the <header> tag
Ok - so.... i have no clue how that Hook is meant to work then lol
Could you share this topic with them? So they can see what we're trying to do and maybe educate us on how to do it properly?
So I received this message from Tutor LMS:
I think This customization will not gonna work with this hook. Send me a screenshot of exactly where after the course enrollment button you want to add the heading. I will try to share the direct code if possible. The hook is not going to work.
And then, they provided me with the following function:
function your_func(){
echo 'here add custimiztion';
}
add_action('tutor_course/single/enroll_box/after_thumbnail', 'your_func');
So if I am right, does this mean that I won't be able to use GeneratePress hook system to display elements? Or is there any easier way than to write custom functions?