[Résolu] Dynamic Meta Data based on custom field, or view data
This support ticket is created Il y a 7 années. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
I would like to alter the meta data in the header dynamically based on URL parameters
I have a view that is on a custom post type
URL like this: lien caché
I would like to use the shortcode:
[wpv-search-term param='catlong']
[wpv-search-term param='location']
to set the Meta Title of the page to Women Looking for Men London.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
Hi Stuart
Toolset doesn't include any capabilities for modifying the page head, only the body, so your solution will require custom coding.
In this case it should be fairly straightforward. You can edit the header.php file from your theme to insert the meta tags you require, and if you want the values of those tags to be generated dynamically with the wpv-search-term shortcode, you can add the shortcode to the PHP template by using the built-in WP function do_shortcode: https://developer.wordpress.org/reference/functions/do_shortcode/
I haven't tested it but for URL parameters I think the wpv-search-term shortcode should work in that context, and the $post object is available by then, so you should be able to use shortcodes to output custom field values for the post being displayed.
Thanks Nigel as always I think this is enough for me to have a play.
One more thing on this I just realised, I only need this to be applied on certain CPT that are dynamically generated content and not on all CPTs. I may be making this way too complicated for myself.
thanks
reference I found for any non php developers reading this lien caché
For a post type of, say, project, that involves copying your theme's single.php to a file named single-project.php which will then be used for displaying single project posts. You can then make edits to that file which will only affect that post type.
In this case, you are making changes to header.php, so you would need to make an alternative header.php file and edit single-project.php to call your alternative using an argument with get_header(): https://codex.wordpress.org/Function_Reference/get_header
It appears what I am trying to do is a little more complex than first thought... none of the above was effective due to the way wordpress now works with the header.
However the fix i managed to achieve is letting WordPress render shortcodes in the page Title.
This allows me to set the URL parameters and then add the search term short codes to the title of the pages like this:
Title: [wpv-search-term param='catlong'] in [wpv-search-term param='location']
renders: <title>A Women Looking For Men in London</title>
Here is how i got around it (took a while to work out, and there may be a better way?).
document_title_parts is the key... and where i found this info lien caché
The only issue with this would be third parties 'could' inject keywords in the the dynamic variables in the URL and then index random pages.... however i see this as pretty unlikely and the same process is actually being done on Gumtree... see here
gumtree com au/s-cheese+maker/k0 (remake the url)
Change cheese+maker and add your own keywords and see what happens.