We are adding a section that loads content from a custom type (created using toolset).
It should display the custom type's archive title and a slider with the items for that custom type.
The slider works great and was easy to implement.
What is the best way to dynamically load the archive title for the custom type?
Note: we are using WPML and ideally the loaded title should change when the selected language changes.
Hi,
Thank you for contacting us and I'd be happy to assist.
To suggest the best way to achieve this, I'll need to understand exactly where this section with the archive title needs to be displayed.
Can you please share temporary admin login details, along with the link to the page where you'd like this title to be?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Thank you for assisting. The section is in an Astra custom layout but I am not asking for this specific scenario only - I would like a general use solution, as this is a common pattern. Please let me know what the options are and I will then be able to select the one best suited to my particular use case.
Thank you for assisting. I am looking for a best practice general use solution, not one specific to a unique use case. Please let me know the options so I can choose the appropriate one.
Thanks for writing back.
As a general requirement, you can register a custom shortcode, which uses the "the_archive_title" function to return the current archive page's title:
https://developer.wordpress.org/reference/functions/the_archive_title/
Example:
function custom_get_archive_title_func( $atts )
{
$a = shortcode_atts( array(
'before' => '',
'after' => ''
), $atts );
return the_archive_title( $a['before'], $a['after'] );
}
add_shortcode( 'custom_get_archive_title', 'custom_get_archive_title_func' );
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
After that, you'll be able to use this shortcode in your archives, like this:
[custom_get_archive_title before='<h1>' before='</h1>']
Note: Feel free to adjust the before and after attribute values as needed, based on the HTML you'd like this title to wrap in.
And this title will be translate friendly too. All you'll need to do is go to WP Admin -> WPML -> String Translation and translate strings for your post type's singular and plural names and the default WordPress string like "Archive".