Wordpress - Inserting dynamic content into a page

As you are building a page template, you can insert in the content of that template whatever you want and use any PHP snippet you want. So, you can continue doing it as you was doing in PHP. For example, this could be your page template:

<?php
/*
Template Name: My template
*/
get_header();

?>
<main>

    <?php

    if( isset( $_GET['pid'] ) ) {

        // Populate your dynamic content here

    }

    ?>


</main>
<?php get_footer(); ?>

But you are correct about title and meta tags of the document, they may be already set. Here you need to hook into wp_title filter and wp_head action, using is_page_template function to check if you are in the page template.

For example, suppose that your page tempalte file name is something like page-mytemplate.php and it is located in the root of your theme:

add_filter( 'wp_title', function( $title, $sep ) {

    if( is_page_template( 'page-mytemplate.php' ) ) {

        // Modify the $title here
        $title = 'my new title';

    }

    return $title;

}, 10, 2 );

add_action( 'wp_head', function() {

    if( is_page_template( 'page-mytemplate.php' ) ) {

        // Echo/print your meta tags here
        echo '<meta name=....>';

    }

} );

The problem

The are a big problem with <meta> tags. WordPress has not a standard way to manage <meta> tags of the docuemnt. If you use any plugin that add <meta> tags, you won't be able to override them unless the plugin offer a way to do it.

Reference

  • wp_title filter
  • wp_head action
  • is_page_template() function