gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
wordpress using php how to check if it's the page about and also if there exists an…
- User
wordpress using php how to check if it's the page about and also if there exists an element called $second_image
- Assistant
In WordPress PHP template files, you can check if the current page is the About page and if a variable
$second_imageexists (is set and not empty) as follows:<?php // Check if current page is 'About' page by slug if ( is_page('about') ) { // Check if $second_image exists and is not empty if ( isset($second_image) && !empty($second_image) ) { // Your code when $second_image exists on About page } else { // $second_image does not exist or is empty } } ?>Explanation:
is_page('about')— checks if the current page slug is "about". You can also use the page ID or title here.isset($second_image)— checks if the variable is defined.!empty($second_image)— checks if it's not empty (not null, not an empty string, etc.)
Alternative ways to check "About" page:
If you know the About page ID, e.g., 42:
if ( is_page(42) ) { // ... }Or by page title:
if ( is_page('About') ) { // ... }