Hi guys,
So I have a few pages where I’d like to make some manual changes to the pages HTML.
My intention is to add extra HTML elements after the first H2 it comes across. This is so that I can optimise my pages for Google SERP rich snippets.
I think I might need to develop my own plugin for this, so where would I start does anyone know?
]]>The reason why I thought a plugin would be more useful is that the elements would change from page to page, and I was thinking I could pass a parameter through when developing the theme itself.
The theme I’m working on is already a child theme, so I might have develop this using a child of a child, if that’s possible…
]]>Are you opposed to editing the child theme directly, for some reason?
What exactly would change from page to page? Is it something that custom fields would be a good use case for?
]]>What would change from page to page:
– a short section of text, with a hyperlink
– sometimes an image
But these two pieces of information must immediately follow the H2 tag, otherwise it may not get picked up by Google snippets.
]]>I think it is technically possible to have a “grand child” theme
Nope, unfortunately it’s not. It’s possible to get the grandparent’s functions and CSS loaded. The problem is its templates. The template loading mechanism only searches the current theme and its possible parent. Any further searches do not occur.
If you are currently modifying your own child theme, then further modifying it is not a problem. The problem is a ton of commercial themes are installed as child themes, using a common parent framework. To cleanly modify such themes, a plugin is the only possibility. Managing templates from a plugin is difficult to impossible. It’s easy to override the loading of the main template. It’s the template parts that are a problem. To customize a template part, a plugin needs to override the main template and make custom calls in place of get_template_part().
Aside from how to modify the theme, custom fields will certainly meet you need. How they are used could be tricky, depending on where the first H2 is output. If it’s part of direct template output, then you need to modify the template. If it’s buried in post content, then you need to hook “the_content” and parse the content for the H2 tag’s first occurrence.
]]>Thanks for the input @bcworkz, I haven’t been under the bonnet of wordpress yet, but quite familiar with other languages, what you said made sense.
]]>