PHP   WordPress   

Get current page number in WordPress using PHP

function getCurrentPageNum($name){
	$URL = $_SERVER['REQUEST_URI'];
	$URLParts = explode("/",$URL);
	$flag = 0;
	foreach ($URLParts as $index => $value){
		if($value == $name) $flag = $index;
	}
	$page = $flag + 1;
	return $URLParts[$page];
} 
$currentPageNum = getCurrentPageNum('page');
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us