I currently worry about performance. The situation is currently:
I want to display content from block editor, or from Gutenberg WordPress editor.
I created a page template and connect with a page.
<?php /* Template Name: Example Template */ ?>
<?php get_header(); ?>
<?php while(have_posts()) : the_post(); ?>
<?php the_content();?>
<?php endwhile; ?>
<?php get_footer(); ?>
What is best way to add elements from the_content(); fun. classes.
eg. I wanna headings tags have an example class but paragraph tags have others. I have three ideas how to ''fix'' this.
First:
Add style tag inside page template and target elements by CSS.
<?php /* Template Name: Example Template */ ?>
<style>
.main h1 { color: red; } .main p { color: green; }
</style>
<?php get_header(); ?>
<?php while(have_posts()) : the_post(); ?>
<div class="main">
<?php the_content();?>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
Second:
Add the target class by jQuery.
<?php /* Template Name: Example Template */ ?>
<?php get_header(); ?>
<?php while(have_posts()) : the_post(); ?>
<div class="main">
<?php the_content();?>
</div>
<?php endwhile; ?>
<script>
$("h1").addClass("color-red");
$("p").addClass("color-green");
</script>
<?php get_footer(); ?>
Or add a class from Gutenberg editor. But I am not sure, what if the user deletes the entire element. Not just content.