Below, you’ll find a detailed guide on how to add the WPLegalPages Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Wplegalpages Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Wplegalpages Plugin and the shortcodes it provides:
"WPLegalPages is a robust Privacy Policy Generator & Terms and Conditions Generator plugin for WordPress. It simplifies the creation of essential legal pages, ensuring website compliance."
- [wplegalpage]
WPLegalPages [wplegalpage] Shortcode
The ‘wplegalpage’ shortcode retrieves and displays the content of a specific legal page. It pulls data from the ‘posts’ table and ‘postmeta’ table, ensuring the post status is ‘publish’ and the post is marked as a legal page.
Shortcode: [wplegalpage]
Parameters
Here is a list of all possible wplegalpage shortcode parameters and attributes:
pid
– The unique ID of the desired legal page
Examples and Usage
Basic example – The following shortcode is used to display a specific legal page by referencing its ID.
[wplegalpage pid=2 /]
Advanced examples
Utilizing the shortcode to display a legal page by referencing its ID and checking if the current user has the “unfiltered_html” capability. If the user has the capability, the content will be decoded.
[wplegalpage pid=2 unfiltered_html=true /]
Another advanced use of the shortcode is to display a legal page by referencing its ID and checking if the current user has the “unfiltered_html” capability. If the user doesn’t have the capability, the content will not be decoded.
[wplegalpage pid=2 unfiltered_html=false /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wplegalpage]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wplegalpage', array( $this, 'wplegalpages_page_shortcode' ) );
Shortcode PHP function:
function wplegalpages_page_shortcode( $atts ) {
global $wpdb;
$atts = shortcode_atts(
array(
'pid' => 0,
),
$atts
);
$pid = $atts['pid'];
$post_tbl = $wpdb->prefix . 'posts';
$postmeta_tbl = $wpdb->prefix . 'postmeta';
$page = $wpdb->get_row( $wpdb->prepare( 'SELECT ptbl.* FROM ' . $post_tbl . ' as ptbl , ' . $postmeta_tbl . ' as pmtbl WHERE ptbl.ID = pmtbl.post_id and ptbl.ID = %d and ptbl.post_status = %s AND pmtbl.meta_key = %s', array( $pid, 'publish', 'is_legal' ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
if ( isset( $page->post_content ) ) {
$content = $page->post_content;
}
if ( is_single() || is_page() ) {
// Check if the current user has the "unfiltered_html" capability
if ( author_can($pid, 'unfiltered_html' ) ) {
// If the user has the capability, decode the content
$content = html_entity_decode( $content );
}
return $content;
}
}
Code file location:
wplegalpages/wplegalpages/public/class-wp-legal-pages-public.php
Conclusion
Now that you’ve learned how to embed the Wplegalpages Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply