2

I'm new to wordpress, but I'm a pretty competent developer. I'm trying to nail down what my client can do to their site. My idea was to create some special 'blocks' for them, which provide the page sections they need with minimal editing requirements.

I know you can create custom blocks with a plugin, but can I create them as part of a theme? If so, can anyone provide me with a link to some helpful information about how to do it?

How would one remove the custom block when the theme is deactivated?

Thanks in advance.

1 Answer 1

-1

Since you don't explain what functionality you're trying to achieve, I assume you want to do one of these thing.

If you're going to put that block in the post content you can achieve that by using WordPress shortcode

If you're going to use that block as part of the layout, you might want to use custom widgets instead.

And both of them can be coded as a standalone plugin or coded in the theme as well. Putting it as a separate plugin means that the user needs to deactivate the plugin if he/she wants to remove the functionality, and if you put it in the theme code, the functionality will just disabled when the theme is deactivated.\

I hope that helps.

5
  • I want to allow the user to add any of 5 or so full width '<section>' elements to their page. Each will be almost complete except for the text and images. there seems to be only.one 'the_content' elements. So i'll have to create custom blicks. I can't use widgets because each page has unique content.
    – Richard
    Commented Feb 20, 2019 at 0:54
  • @JacobPeattie That's an interesting... if deliberately cryptic article. It seems to suggest that 'the_content' is parsable. Even if that were the.case I'd need a neat way of adding.sections. do you propose simply parsing out <p> tags and replacing them? that would seem a bit brittle? Do you know if I can create and register custom blocks within my theme's functions.php?
    – Richard
    Commented Feb 20, 2019 at 2:02
  • @Richard The link was just for hamdirizal's benefit, since he didn't seem to be aware that "Blocks" are a thing in WordPress now, it wasn't really to address your question. Commented Feb 20, 2019 at 2:09
  • @JacobPeattie i think.i can create 'block.templates'. But again the documentation for that is sketchy. It doesnt tell me whether i.define.the block template array.in a theme or a plugin. The learning curve of wordpress reminds me of when i.was learning to use Maven.
    – Richard
    Commented Feb 20, 2019 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.