• Resolved greencrest

    (@greencrest)


    I’m running into a strange PHP alert on my staging site. I have a couple of custom sidebars that I’m calling on the page template like so:

    ?php get_sidebar(parts); ?>
    <?php get_sidebar(cos); ?>

    They show up fine but getting an alert right before stating:

    Warning: Use of undefined constant parts – assumed ‘parts’ (this will throw an Error in a future version of PHP) in /nas/content/staging/airtechsite/wp-content/themes/air2017-child/parts-page.php on line 30

    Now I’m not getting those on the live site, only on the staging, which is using a different URL. Anyone know what’s causing this warning and how I can fix it? I’m running php 7.2. Thanks.

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    So where is parts defined?

    Thread Starter greencrest

    (@greencrest)

    its a file named sidebar_parts.php. Its not dynamic so I never had a need to register it if that’s what you’re asking.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’m confused.
    This is your code:

    
    get_sidebar(parts);
    

    But you aren’t defining the “parts” bit, where is that coming from? Or are you copying code from somewhere else?

    Thread Starter greencrest

    (@greencrest)

    the custom sidebar is named sidebar-parts.php. when adding a custom sidebar, WordPress recognizes the sidebar- as a sidebar file and you only need the “parts” name to pull it.

    From https://developer.www.ads-software.com/reference/functions/get_sidebar/

    Simple call
    Assume you have file wp-content/yourTheme/sidebar-nice-bar.php. The way you can include this sidebar in your page is:
    1

    <?php get_sidebar(‘nice-bar’); ?>

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    But in your example, you are not passing a string. You are passing a variable “parts” for which is undefined.

    Thread Starter greencrest

    (@greencrest)

    sorry, I’m a novice when it comes to PHP. So should it look like this instead?

    <?php get_sidebar('parts'); ?>

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Yes or you could define the variable above that line, which ever best works for you.

    
    <?php
    
    $parts = 'parts';
    
    get_sidebar($parts); 
    
    ?>
    
    Thread Starter greencrest

    (@greencrest)

    that fixed it. Any idea why I’m only getting that warning on the staging version?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your live version probably suppresses errors – if you check the error log on your live version you may still see the issue there. Just not on your live website.

    Thread Starter greencrest

    (@greencrest)

    thanks.

    Thread Starter greencrest

    (@greencrest)

    thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘undefined constant parts with custom sidebar’ is closed to new replies.