Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable shortcode expansion for oik based shortcodes #2

Open
bobbingwide opened this issue Oct 2, 2024 · 2 comments
Open

Enable shortcode expansion for oik based shortcodes #2

bobbingwide opened this issue Oct 2, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Oct 2, 2024

A while ago, in WordPress 6.2, the ability to include shortcode in template parts was removed.
The call to do_shortcodes() was no longer being invoked on template parts.
This caused a bit of a kerfuffle.
But it wasn't a problem for my FSE themes since I was overriding template part processing.
The problem's now been resolved but caused me a bit of a headache as I tried to remember what to do...

I got nowhere for quite a while yesterday evening until I realised that I hadn't enabled my oik shortcodes.
The fix was to add some logic in functions.php.

/**
 * Enables oik based shortcodes.
 */
function oobit_init() {
    if (function_exists('bw_add_shortcode')) {
        do_action("oik_add_shortcodes");
  }
}
add_action( 'init', 'oobit_init', 20 );

During init processing we check if the function bw_add_shortcode is present. If it is then oik has been loaded so we should be able to run the oik_add_shortcodes action to cause oik and other plugins to lazy load shortcodes.

I'll need to use several oik based shortcodes which haven't yet been replaced by blocks ( e.g. [bw_blogs] ) and therefore probably need to include these in template parts rather than directly into templates.

Note: Rather than having every theme that's dependent upon oik to implement this it would be better if

  • either oik could detect the need to invoke the action.
  • or all the shortcodes are implemented as blocks.
@bobbingwide bobbingwide added the enhancement New feature or request label Oct 2, 2024
@bobbingwide bobbingwide self-assigned this Oct 2, 2024
@bobbingwide
Copy link
Owner Author

or all the shortcodes are implemented as blocks.

Enabling me to replace the template part currently called network-sites-theme.html

<!-- wp:shortcode -->
[bw_blogs]
<!-- /wp:shortcode -->

with a simple server side rendered block

<!-- wp:oik/bw_blogs /-->

@bobbingwide
Copy link
Owner Author

Rather than having every theme that's dependent upon oik to implement this it would be better if
either oik could detect the need to invoke the action.

I've prototyped a solution that oik can use to improve support for block themes.

See bobbingwide/oik#233

Note that this improvement to oik may not totally negate the need for functions.php.
It may still be necessary to implement some or all of the following

  • custom block styles
  • filter functions to adjust rendered block output - eg render_block_core/shortcode
  • block override logic

For information about using filter functions to enable shortcodes to be used in the query block see bobbingwide/fizzie#28 (comment)

It may also be possible to implement the relevant code in a plugin. See the bigram plugin for several block rendering overrides including the classic block (filter name render_block_).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant