• [ Moderator note: moved to Fixing WordPress. ]

    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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • It really depends how the HTML is being churned out. If it’s through a theme, you might want to look into developing a child theme to override the markup. No plugin would be necessary in this case.

    Thread Starter cooper1210

    (@cooper1210)

    Thanks Leland, I will look into that.

    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…

    I think it is technically possible to have a “grand child” theme, but I don’t know much about it. At that point, you have to ask yourself why you’re abstracting on top of the original theme so much, and if there are ways to make themes higher up on the “family tree” more flexible.

    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?

    Thread Starter cooper1210

    (@cooper1210)

    +1 for custom fields. I’m yet to look into this in more detail.

    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.

    Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter cooper1210

    (@cooper1210)

    Yup, this is the problem, in that the template is installed as a child theme.

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to Edit HTML that is churned out by PHP’ is closed to new replies.