Created
January 27, 2022 19:36
-
-
Save joeydi/4f3b9c1e50180396d558d482a3435af5 to your computer and use it in GitHub Desktop.
React / WordPress Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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