Use the legal pages post type in your theme and plugin code
TermsFeed AutoTerms stores every legal page as a post of the hierarchical post type wpautoterms_page, which your code queries, links, and displays like a WordPress page. The examples use only WordPress core functions and run in a theme, child theme, or plugin.
Properties of the wpautoterms_page post type
| Property | Value | What it means for your code |
|---|---|---|
| Name | wpautoterms_page |
The value of post_type in a query, and the post type argument of core functions such as get_page_by_path() |
| Hierarchical | Yes | A legal page takes a parent and a menu order, as a page does, and the address of a child page adds the path of its parent |
| Public and queryable | Yes | Each published legal page has its own address, and is_singular( 'wpautoterms_page' ) is true on it |
| Site search | Excluded | Legal pages never appear in site search results, and a query with 'post_type' => 'any' leaves them out |
| Archive | Yes, at the legal pages slug | get_post_type_archive_link( 'wpautoterms_page' ) returns the archive address, /termsfeed/ by default |
| Query var | wpautoterms_page |
The query variable that holds the page slug in a plain permalink |
| Taxonomy | category |
Legal pages take post categories; the Categories screen is hidden from the TermsFeed menu |
| Supports | title, editor, revisions, page-attributes, custom-fields, excerpt, author |
The boxes the editor shows, and the fields your code reads with core functions |
| Export | Yes | Tools > Export includes legal pages |
| REST API | Not exposed | No /wp-json/wp/v2/ route lists legal pages, and the plugin does not register a REST route of its own |
| Editor | Classic editor | Legal pages open in the classic editor, never in the block editor |
The post type registers early on init, before any callback at the default priority 10. Run code right after it registers with the wpautoterms_registered_cpt action in TermsFeed AutoTerms Action Hooks and Filters.
How to query legal pages with WP_Query and get_posts()
Name the post type wpautoterms_page every time, because 'post_type' => 'any' leaves legal pages out, and the status publish, so drafts and private pages stay out of a list for visitors. The first example prints every published legal page as a linked item of a <ul class="mytheme-legal-pages"> list, in the order of the Page Attributes box, then by title. It prints nothing while no legal page is published.
<?php
$mytheme_legal_pages = new WP_Query(
array(
'post_type' => 'wpautoterms_page',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => array(
'menu_order' => 'ASC',
'title' => 'ASC',
),
'no_found_rows' => true,
)
);
if ( $mytheme_legal_pages->have_posts() ) {
echo '<ul class="mytheme-legal-pages">';
while ( $mytheme_legal_pages->have_posts() ) {
$mytheme_legal_pages->the_post();
printf(
'<li><a href="%1$s">%2$s</a></li>',
esc_url( get_permalink() ),
esc_html( get_the_title() )
);
}
echo '</ul>';
wp_reset_postdata();
}
?>
The second example prints the 3 legal pages you changed most recently, each with its link and the date its "Last updated" line shows.
<?php
$mytheme_updated_pages = get_posts(
array(
'post_type' => 'wpautoterms_page',
'post_status' => 'publish',
'numberposts' => 3,
'orderby' => 'modified',
'order' => 'DESC',
)
);
foreach ( $mytheme_updated_pages as $mytheme_page ) {
printf(
'<p><a href="%1$s">%2$s</a>, last updated %3$s</p>',
esc_url( get_permalink( $mytheme_page ) ),
esc_html( get_the_title( $mytheme_page ) ),
esc_html( get_the_modified_date( '', $mytheme_page ) )
);
}
?>
How to link a legal page by its slug
Link a legal page by its slug, such as privacy-policy, or the full path of a child page, such as policies/cookies-policy. This function returns the address of a published legal page, or an empty string while the page is missing or still a draft.
/**
* Returns the permalink of a published TermsFeed AutoTerms legal page, or ''.
*
* @param string $path Slug of the legal page, or parent/child path of a child page.
* @return string
*/
function mytheme_legal_page_url( $path ) {
$page = get_page_by_path( $path, OBJECT, 'wpautoterms_page' );
if ( ! $page || 'publish' !== get_post_status( $page ) ) {
return '';
}
return get_permalink( $page );
}
This template code prints a link to the Privacy Policy that the questionnaire created. It prints nothing while that page is missing or still a draft.
<?php
$mytheme_privacy_url = mytheme_legal_page_url( 'privacy-policy' );
if ( '' !== $mytheme_privacy_url ) {
printf(
'<a class="mytheme-privacy-link" href="%s">%s</a>',
esc_url( $mytheme_privacy_url ),
esc_html__( 'Privacy Policy', 'mytheme' )
);
}
?>
The [wpautoterms] shortcodes give the same link, title, and date in content. Copy each one from Legal Page Shortcodes for WordPress.
In PHP, run a shortcode with do_shortcode() and escape the link. These 3 lines print the title, the address, and the "Last updated" date of the Privacy Policy.
<?php echo do_shortcode( '[wpautoterms page_title="privacy-policy"]' ); ?>
<?php echo esc_url( do_shortcode( '[wpautoterms page_link="privacy-policy"]' ) ); ?>
<?php echo do_shortcode( '[wpautoterms last_updated_date="privacy-policy"]' ); ?>
Slugs and dates of generated legal pages
Each questionnaire gives its page a fixed slug: privacy-policy, terms-and-conditions, or cookies-policy. A second page of the same type is published with a number, such as privacy-policy-2, so code that looks up privacy-policy finds the first page. A custom legal page takes its slug from its title.
The "Last updated" line and the "Last Effective Date" column read the modified date of the post, so any save moves them. The Update Notices kit reads it too, but skips a save within 60 seconds of publishing. Read it with get_the_modified_date() or get_post_modified_time(), never the publish date.
Permalinks, the legal pages slug, and the archive
Legal pages live under the legal pages slug, termsfeed by default: /termsfeed/privacy-policy/ with pretty permalinks, /termsfeed/policies/cookies-policy/ for a child page, and the archive at /termsfeed/. With plain permalinks, the address carries the query variable instead, such as /?wpautoterms_page=policies/cookies-policy, and the "Legal pages slug" setting has no effect.
Build every link with get_permalink() and get_post_type_archive_link( 'wpautoterms_page' ), never with a typed path, so the links follow a change of the slug. Change the slug with WordPress Legal Page Settings.
Display legal pages with theme templates
The plugin does not add a front-end template, so WordPress picks a theme template as for any custom post type.
| Template file | Displays |
|---|---|
| The page template chosen in the Template select | The legal page you chose it for |
single-wpautoterms_page-privacy-policy.php |
The legal page with the slug privacy-policy |
single-wpautoterms_page.php |
Every legal page |
single.php, singular.php, index.php |
Every legal page with no chosen page template, in a theme without single-wpautoterms_page.php or a matching slug file |
archive-wpautoterms_page.php |
The archive at the legal pages slug |
archive.php, index.php |
The archive, in a theme without archive-wpautoterms_page.php |
The Template select of a legal page lists the page templates of a classic theme, or the custom templates of a block theme. A block theme takes the same file names as .html files in its templates folder.
The generated text starts with its "Last updated" line and never repeats the title, so print the title in the template, as this single-wpautoterms_page.php for a classic theme does.
<?php
/**
* Template for TermsFeed AutoTerms legal pages.
*/
get_header();
while ( have_posts() ) :
the_post();
?>
<main id="primary" class="site-main mytheme-legal-page">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
</main>
<?php
endwhile;
get_footer();
With this file in the theme folder, every published legal page prints its title as an <h1> heading and carries the mytheme-legal-page class on its <main> element.
A theme file does not replace the markup of the notices and the footer legal links. Style it with the selectors in TermsFeed AutoTerms CSS Classes and Containers.
Legal pages in the WordPress privacy and WooCommerce settings
The AutoTerms plugin adds legal pages to the page list of Settings > Privacy, drafts included. It adds them to the "Privacy policy page" and "Terms and conditions page" lists of Appearance > Customize > WooCommerce > Checkout too. The "Terms and conditions" search in WooCommerce > Settings > Advanced finds regular pages only. On a store with the Checkout block, set the terms page with wp option update woocommerce_terms_page_id <ID>, with the ID of the legal page.
Once a published legal page is the WordPress privacy page, get_privacy_policy_url() and the_privacy_policy_link() link it. Choose the pages in the admin with the steps in How to choose a legal page as the WordPress Privacy Policy page and How to choose legal pages in WooCommerce.