2023-09-27

$wp_customize is not displaying section, control, settings for custom page template - Wordpress

$wp_customize isn't showing the add section, control or settings i've set up for a custom template under the "Customize" feature on wordpress.

I figured out that initially my require_once path was wrong and fixed that to the below

elseif  (is_page('annual-report')) {
require_once(TEMPLATEPATH . '\pageFunctions\annualReportFunctions.php');

   // include_once(dirname(__DIR__).'/BOAT-wordpress-theme/pageFunctions/annualReportFunctions.php');
   }

I intentionally made an error in the annualReportFunctions.php file because I wanted to test and be sure if wordpress was actually able to locate and load that file now. Good news is that an error message confirmed it can!

The bad news is that when I took the error out although WP is reading the file associated with the page it's on, it's still not showing the options in the customize feature.

I reviewed https://developer.wordpress.org/themes/customize-api/customizer-objects/ a few times to try and understand if I'm missing something in the section, control or settings section that would prevent it from displaying.

I commented out all the code in my annualReportFunctions.php file and posted in the example code from here: https://developer.wordpress.org/reference/hooks/customize_register/ to see if it would show up, and nothing showed up.

I've looked up my problem on stackoverflow and haven't been able to figure out what i'm doing wrong yet.

I'm incredibly frustrated and confused - I would really appreciate any help if anyone has any insight. It's loading the web page just fine without any error codes. Thank you for any insight

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' );

function add_checkPage() {
//Find Your Trip Page
if (is_page('find-your-trip')) {
   require_once(TEMPLATEPATH . '\pageFunctions\findYourTripFunctions.php');
}
//Homepage
elseif (is_page('home')) {
   require_once(TEMPLATEPATH . '\pageFunctions\homeFunctions.php');
}
//Who We Are Page
elseif (is_page('who-we-are')) {
   require_once(TEMPLATEPATH . '\pageFunctions\whoWeAreFunctions.php');

}
//What We Do Page
elseif (is_page('what-we-do')) {
   require_once(TEMPLATEPATH . '\pageFunctions\whatWeDoFunctions.php');

}
//Support Our Mission Page
elseif (is_page('support-our-mission')) {
   require_once(TEMPLATEPATH . '\pageFunctions\supportOurMissionFunctions.php');

}
   //Annual Report Page
elseif  (is_page('annual-report')) {
require_once(TEMPLATEPATH . '\pageFunctions\annualReportFunctions.php');

   // include_once(dirname(__DIR__).'/BOAT-wordpress-theme/pageFunctions/annualReportFunctions.php');
   }
}
// wp_reset_query();

         ?>

page-{annualReport}.php file:

<?php
/*
 * Template Name: Annual Report
 * description: >-
Annual report page */ ?>
<?php get_header();
add_css();
add_checkPage();
add_script(); ?>
<body>
<div class="sectionHeader">
      <div class="annualReport headerBanner">
      <img src="<?php echo wp_get_attachment_url(get_theme_mod('boat-annualreport-callout-image')) ?>" />
      </div>
      <div class="textBlockUnanimated rightBlock">
      <h1><?php echo get_theme_mod('boat-annualreport-callout-headline') ?></h1>

        <p>
          <a
            href="https://drive.google.com/file/d/1Vapxlp-5_y_MpRUFZllO7XojiHKuDVwa/view"
          >
            <button class="intro btn enterSite" id="homepage">
              <span class="spanText">2022</span>
            </button></a
          >
          <a
            href="https://theboatbus.com/wp-content/uploads/2022/01/BOAT-Annual-Report-2020-2021.pdf?189db0&189db0"
          >
            <button class="intro btn enterSite" id="homepage">
              <span class="spanText">2020-2021</span>
            </button></a
          ><br />
          <a
            href="https://theboatbus.com/wp-content/uploads/2022/01/BOAT-Annual-Report-2019.pdf?189db0&189db0"
          >
            <button class="intro btn enterSite" id="homepage">
              <span class="spanText">2019</span>
            </button></a
          >
        </p>
      </div>
    </div>
<?php get_footer(); ?>

annualReportFunctions.php file:

   <?php

   function boat_annualreport_callout($wp_customize) {

   $wp_customize->add_section('boat-annualreport-callout-section',
    array ('title' => 'Annual Reports'
));

      $wp_customize->add_setting('boat-annualreport-callout-image', array(
         'theme_supports' => '',
         'default' => '',
         'transport' => 'refresh',
         'sanitize_callback' => '',
          'sanitize_js_callback' => ''
      ));
   
      $wp_customize->add_control( new WP_Customize_Cropped_Image_Control($wp_customize, 'boat-annualreport-callout-image-control', array (
      'type' => 'image',
      'label' => 'Annual Report',
      'section' => 'boat-annualreport-callout-section',
      'settings' => 'boat-annualreport-callout-image',
      'height' => 590,
      'width' => 1920
      
      )));
   }
      add_action('customize_register', 'boat_annualreport_callout');

?>


No comments:

Post a Comment