Get current page attributes in WordPress.
Install via composer:
composer require grottopress/wordpress-page
<?php
declare (strict_types = 1);
use GrottoPress\WordPress\Page;
// Instantiate
$page = new Page();
// `$page` now represents the current page (where it was instantiated)
// Get page title
echo $page->title();
// Get page description
echo $page->description();
// Get page URL
echo $page->URL('full');
// Get page number
echo $page->number();
// Get page type
print_r($page->type());
// Check if page is single post
if ($page->is('single')) {
echo 'Single!';
} else {
echo 'Not single :(';
}
// Check if page is 'tutorial' custom post archive
if ($page->is('post_type_archive', 'tutorial')) {
echo 'Yay!!! Tutorials.';
} else {
echo 'Nope :(';
}
Run tests with composer run test
.
- Fork it
- Switch to the
master
branch:git checkout master
- Create your feature branch:
git checkout -b my-new-feature
- Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit
- Push to the branch:
git push origin my-new-feature
- Submit a new Pull Request against the
GrottoPress:master
branch.