A question regarding outputting the last piece of the permalink of my (custom post) in Wordpress. Here is the situation:
I am using Fullpage.js to display all my posts of a custom post type. This is working perfectly but now I need to add a data-anchor for every section/post. This data-anchor needs to be the last piece of the specific post's permalink. For example:
localhost/testtheme/projects/painting/
But I need the last piece of this url to be outputed. This would be:
/painting/
I am using the make_link_relative function of Wordpress but this also outputs my /testtheme/projects/ part of the permalink and I don't want this to show up.
I am going to add the snippet code a wrote to beter demonstrate what I mean. Thank you in advance for your help.
Please see line 21 for the data-anchor problem.enter image description here
Kind regards
You're looking for the post's slug. This can be retrieved from the post object by accessing the 'post_name' attribute, as shown below:
<?php echo $post->post_name; ?>