Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Page Generator Pro: Programmatically Process Spintax and Block Spintax
<?php
/**
* Make sure to run this after WordPress' init hook has completed.
*/
function process_block_spintax_and_spintax_example( $text ) {
// Bail if Page Generator Pro isn't active
if ( ! function_exists( 'Page_Generator_Pro' ) ) {
return new WP_Error( 'error', __( 'Page Generator Pro not active.' ) );
}
// Perform Spintax
$spin = Page_Generator_Pro()->get_class( 'spintax' )->process( $text );
if ( is_wp_error( $spin ) ) {
return $spin;
}
// Perform Block Spintax
return Page_Generator_Pro()->get_class( 'block_spin' )->process( $spin );
}
$spin = process_block_spintax_and_spintax_example( '#p#
#s#
{Writing|Creating} {content|articles} is {a lot of fun|rewarding experience}.
{Creating|Publishing} {articles|posts} is a {great SEO tool|fantastic way to generate unique content}.
#/s#
#s#
When done correctly, it captures the audience’s attention.
The audience is immersed in the story, and continue to read.
#/s#
#/p#' );
if ( is_wp_error( $spin ) ) {
// Something went wrong e.g. invalid spintax
// Handle this error as you need
echo $spin->get_error_message();
} else {
echo $spin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment