The Definitive Guide to Setting Up WordPress in 2024: A Bristol Freelance Web Developer’s Essential Setup
In the ever-evolving landscape of website development, staying ahead of the curve...
Add this to your functions.php to add a class to all pages within a tree:
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$cpid = get_the_ID();
$parents = get_post_ancestors( $post->ID ); // get the ancestors
$ancestorid = ($parents) ? $parents[count($parents)-1]: $post->ID;
if(($post->post_parent==$pid||$cpid==$pid||$ancestorid==$pid))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
// Then use this conditional anywhere in your template files:
if ( is_tree( //page id here ) ) :
// Do something...
endif; ?>
Reference – css tricks blog post
Wordpress Function, WordPress Tips
Share
In the ever-evolving landscape of website development, staying ahead of the curve...
In the digital realm, your website serves as the cornerstone of your...
In the ever-evolving world of e-commerce, having a robust and flexible platform...
Add this code to your functions.php file to add the dimensions to the image object array for svgs. add_filter( 'wp_get_attachment_image_src',...
For me, the ACF plugin is a standard install for every WordPress project. Its a great tool for developers to...
Simple bit of jQuery to add an active class to the current navigation item based on the page url. jQuery("nav...