I'm trying to make it so that when someone goes into WordPress and goes to update a section of a page, WordPress only loads the customize options for that page that they're specifically editing $wp_customize->add_section
. Right now it's showing all of the sections for all of the pages on the website and is not manageable.
EDIT: Trying another approach that I think is cleaner but still having the same issue...edited the code to reflect what I'm currently working with:
beginning of functions.php file:
<?php
function add_css()
{
wp_register_style('style', get_template_directory_uri() . '/assets/css/style.css', false,'1.1','all');
wp_enqueue_style( 'style');
}
add_action('wp_enqueue_scripts', 'add_css');
function add_script()
{
wp_register_script('js-script', get_template_directory_uri() . '/assets/js/scripts.js', array ( 'jquery' ), 1.1, true);
wp_enqueue_script( 'js-script');
}
add_action('wp_enqueue_scripts', 'add_script');
add_theme_support( 'menus' );
global $template;
global $currentPage;
function boat_homehero_callout($wp_customize) {
if (is_page('home')) {
$currentPage = 'Home';
echo $currentPage;
$wp_customize->add_section('boat-homehero-callout-section', array ('title' => 'Homepage Hero Section'));
?>
end of my functions.php file:
<?php
wp_reset_query();
if (is_page('find-your-trip')) {
boat_findyourtrippage_callout();
} elseif (is_page('home')) {
boat_homehero_callout();
} elseif (is_page('who-we-are')) {
boat_whoweare_callout();
} elseif (is_page('what-we-do')) {
boat_partnership_callout();
} elseif (is_page('support-our-mission')) {
boat_supportourmission_callout();
} // else (is_page('annual-report')) {
elseif (is_page('annual-report')){
boat_annualreport_callout();
} else {
boat_homehero_callout();
}
?>
Thank you for any guidance!
I've tried using is_page() https://developer.wordpress.org/reference/functions/is_page/ . I've spent days trying to troubleshoot and reading other Stackoverflow answers and I'm stuck. This is my first custom WordPress template build and I've read some answers saying to use wp_reset_query() and other answers saying to never use wp_reset_query(). I tried using it and I'm not sure if I placed it in the wrong area, but it didn't work for me.
Or is it something else entirely I'm missing? I'd really appreciate any help at all. I checked the WordPress pages permalink section and the permalink matches what I'm calling with the is_page()
function.
I'm also using localwp
for editing the template locally. https://localwp.com/
2nd Edit: Found out how to view the console on WordPress and am getting the error below when I log $currentPage; taking a look at things...
PHP Warning: Undefined variable $currentPage in C:\Users\Melis\Local Sites\boat\app\public\wp-content\plugins\wp-console\includes\Core\Console\RestController.php(139) : eval()'d code on line 1
#1 C:\Users\Name\Local Sites\boat\app\public\wp-content\plugins\wp-console\includes\Core\Console\RestController.php(139): eval()