check if is_page and page template id is 10 in wordpress
To check if the current page is a WordPress page and if the page template ID is 10, you can use the following code in your theme's functions.php file or in a custom plugin:
if ( is_page() && get_page_template_id() == 10 ) {
// The current page is a WordPress page with template ID 10
// Add your code here
}
Explanation:
is_page()is a conditional function that checks if the current context is a single page.get_page_template_id()is a custom function that retrieves the template ID of the current page. You need to define this function in your code. Here's an example implementation:
function get_page_template_id() {
$post_id = get_queried_object_id();
$template_id = get_post_meta( $post_id, '_wp_page_template', true );
return $template_id;
}
Make sure to replace 10 with the actual ID of the page template you want to check
原文地址: https://www.cveoy.top/t/topic/iCzu 著作权归作者所有。请勿转载和采集!