- This topic has 8 replies, 3 voices, and was last updated 3 years, 8 months ago by David.
-
AuthorPosts
-
August 4, 2020 at 5:13 am #1386775Stephen
Hello,
I’ve created a Header Element for Product Category Archives. It’s a simple header section that needs to pull in a title and description. I can do this with the code below:
<h1>{{post_title}}</h1>
<p>[term_description]</p>However, this doesn’t work the way I need it for product filtering pages. I’m looking to have it so the title and description pulled in are from the seo meta of the page that you’re currently on.
Linked the site below. Basically ‘Carpets’ is the product category name. ‘a-colour-groups-beige’ is the url suffix when the ‘beige’ filter is selected. The filter plugin allows for custom SEO rules, so the ‘beige’ selection has it’s own meta description and title. It’s this information that needs to be in the header. Is there are shortcode or template tag I can use in this header element to pull this in?
Thanks in advance
August 4, 2020 at 5:26 am #1386786DavidStaffCustomer SupportHi there,
you could create your own shortcodes if you know the meta keys used by the SEO rules plugin.
Example for a[SEO-Title]
shortcodeadd_shortcode( 'SEO-Title', function() { // Get your title $seoTitle = get_post_meta( get_the_ID(), 'ADD-THE-POST-META-KEY-HERE', true ); // Output title if complete if ( $seoTitle ) { ob_start(); echo $seoTitle; return ob_get_clean(); } });
August 4, 2020 at 6:18 am #1386828StephenThanks for the reply David.
I’m not sure what the meta keys are. The plugin is premmerce and they aren’t overly helpful. Do you know what they should look like and where I could find them?
I think their seo plugin works alongside Yoast.
If it were using yoast meta keys would the snippet look like this:add_shortcode( 'SEO-Title', function() { // Get your title $seoTitle = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true ); // Output title if complete if ( $seoTitle ) { ob_start(); echo $seoTitle; return ob_get_clean(); } });
August 4, 2020 at 6:26 am #1386846DavidStaffCustomer SupportThat would be correct for Yoast – might be worth trying them as there is a chance premmerce is writing into them.
If not there is this plugin which will display post meta – although if its dynamic it may not show:
August 4, 2020 at 8:16 am #1387099StephenUnfortunately that plugin doesn’t display the metadata on the premmerce seo rule section.
The Yoast meta keys don’t seem to work either. I’m looking through the premmerce seo plugin in the plugin editor to see how it works but it’s alien to me. I can see there are references to Yoast but can’t see the connection or what the meta keys could be.August 4, 2020 at 10:23 am #1387240StephenI added Yoast and tested the shortcode made using the above snippet but it doesn’t seem to be working.
<h1>[SEO-Title]</h1>
<p>[SEO-Description]</p>The h1 and p tags have nothing in them on the frontend.
August 4, 2020 at 12:58 pm #1387379TomLead DeveloperLead DeveloperHi there,
That likely means the post meta keys aren’t correct, or there’s no value added to them.
We’re not aware of that plugin specifically, so we wouldn’t know what they’d name their custom fields, unfortunately.
August 5, 2020 at 1:33 am #1387861StephenHi Tom,
I’ve disabled the Premmerce plugin and just have Yoast but the shortcode suggested isn’t pulling through the meta title and description on any of the pages, wherever I put it.I might not even need it. There might be another solution to my SEO issue. Carpets is a ‘Product Category Archive’ and pulls through the header element I want (because I can target that specifically). I need a way to target the sub sections of Carpets, or target specific URLs with a hook or a header element. Is there a way to do that?
August 5, 2020 at 5:53 am #1388090DavidStaffCustomer SupportThere’s a similar request here where the user wanted URLs for display rules:
https://generatepress.com/forums/topic/feature-request-6/#post-1385716
Instead of the
generate_hook_element_display
filter you can use thegenerate_header_element_display
https://docs.generatepress.com/article/generate_header_element_display/
-
AuthorPosts
- You must be logged in to reply to this topic.