This is an example how to add some OG tags for Facebook:
Create a hook to a function on the wp_head
action,
// if on a single post screen, generate and insert facebook:OG tags. ##
add_action( 'wp_head', 'wpse381199_og_tags', 12 );
Then create a function to generate the OG tags
function wpse381199_og_tags(){
// get the current post object ##
$the_post = get_post();
// bulk if no post
if ( ! $the_post ){ return false; }
// check we are on a single post or page, if not bulk ##
if (
! \is_single()
&& ! \is_page()
) {
// h::log( 'Not a single post or page query' );
return false;
}
// get all the data we need. ##
$array = [];
$array['title'] = $the_post->post_title;
// add all other tag elements you want to array here and add a new tag for each value in the HTML below.
?>
<meta property="og:title" content="<?php echo ( \esc_html( $array['title'] ) ); ?>" />
<?
}