Skip to content

Instantly share code, notes, and snippets.

@joeydi
Created January 27, 2022 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeydi/4f3b9c1e50180396d558d482a3435af5 to your computer and use it in GitHub Desktop.
Save joeydi/4f3b9c1e50180396d558d482a3435af5 to your computer and use it in GitHub Desktop.
React / WordPress Integration
<?php
// The include_app function loads the React app and merges in the SEO tags and post content for indexing
// Basically a poor man's server-side rendering - if I were to do this again I'd probably use Next.JS
function include_app()
{
$index = file_get_contents(EFA::theme_path('progress-meter/app/build/index.html'));
$end_head = '</head>';
$seo_tags = YoastSEO()->meta->for_current_page()->get_head()->html;
$index = str_replace($end_head, $seo_tags . $end_head, $index);
$start_body = '<body>';
$post_content = apply_filters('the_content', get_the_content());
$post_content = "<div class=\"d-none\">$post_content</div>";
$index = str_replace($start_body, $start_body . $post_content, $index);
echo $index;
}
<?php
// Instead of a typical WordPress template, with get_header(), get_footer(), etc.
// We just call this function...
include_app();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment