- This topic has 1 reply, 2 voices, and was last updated 3 years, 4 months ago by
Leo.
-
AuthorPosts
-
December 8, 2022 at 9:48 am #2454857
Graeme
Hi there,
I’ve been working on this for a while and wanted to check with the experts if there is anything wrong with this solution, as, so far it seems to be working.
Objective is to have custom breadcrumbs on my pages; with nav html visible to the user and ld+json schema fire in the header for google to see.
For the ld+json breadcrumb schema:
I’m using a hook header element in wp_header with php enabled and the following script here, with a custom field on the pages I want it on called “schema”<?php $schema = get_post_meta(get_the_ID(), 'schema', true); echo $schema; ?>In the custom field on the page, “schema”, I then enter my ld+json breadcrumb schema and then this is working well, no issues, google sees it.
Next I want some nav, HTML, with a link to parent page visible to the user and I want to show it directly above or directly below the Generatepress generated H1 page title.
To do so I came up with the following:
Hook header element with the hook set “generate_before_content”, with PHP enabled and then the following php code:
<?php $schema2 = get_post_meta(get_the_ID(), 'schema2', true); echo $schema2; ?>Then on my page, another custom field called “schema2” this time, and then on the page, in the “schema2” custom field I enter the following nav class:
Nav html visible to user on page
<nav class="breadcrumb" aria-label="breadcrumbs"> <a href="https://mywebsite.com/page1/">Parent Topic</a> <span class="separator"> » </span> <span class="last">Page1 Title</span> <p></p> </nav>This seems all to be working, but before I implement it on more pages I wanted to ask if you see anything amiss or that should be changed?
Thank you very much for any and all input!
Cheers
December 8, 2022 at 12:17 pm #2454988Leo
StaffCustomer SupportHi there,
I’d say that if you don’t notice any issues then it’s a good solution!
If you’d like more audience for the question then I’d recommend posting this in a WP general forum like Stack:
https://wordpress.stackexchange.com/It’s a great resource for non-theme related questions 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.