[Resolved] Best way to add inline php to footer

Home Forums Support [Resolved] Best way to add inline php to footer

Home Forums Support Best way to add inline php to footer

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2206166
    Sebastian

    Hi guys,

    I have designed a 4-col footer and would appreciate your input for how to actually implement it in the theme.

    In my footer I would like to add dynamic links such as login / logout link, my orders link, my deliveries link etc. These links should render different depending of, if the visitor is logged in or not.
    At first I tried the widgets but found myself extremely locked in and limited not able to customize anything really.

    In the past I would just add everything into the footer.php file and be done with it.

    Example for my simple login/logout links:

    <li>
    <?php
      if(is_user_logged_in) { ?>
        <a href="<?php echo wp_logout_url(); ?>">Logout</a>
    <?php } else { ?>
      <a href="<?php echo wp_login_url(); ?>">Login</a>
    <?php } ?> </li>

    But now with all the block functionality I don’t know if this is the right way to go? I mean, what about all these do_actions() ? Is it safe to input html between these or are there better, more future proof ways of doing this? I know there’s this thing you call elements. I just don’t see how or where it should go together…

    I hope I’m making sense here.
    Thanks.

    #2206341
    David
    Staff
    Customer Support

    Hi there,

    if you’re using Blocks then WP core does provide a Login / Logout Block for that purpose.
    Are the other links dynamic ? If so then they may need converting to shortcodes. Let me know

    #2220841
    Sebastian

    Hi David,

    Yes, just about every link in the column will be dynamic. I would like to have the following links for logged in users:

    • Login / logout
    • My Account
    • My orders (Account Page->Orders)
    • My Shippings/deliveries (not sure yet if or how this would be implemented)
    • My Adresses
    #2221069
    David
    Staff
    Customer Support

    Simplest option would be to use a plugin like this:

    https://en-gb.wordpress.org/plugins/custom-sidebars/

    Then you could create a different footer widget area for logged in and logged out users.

    Alternative is to create a Shortcode to display the content in the footer.

    #2223301
    Sebastian

    Well, I would really prefer not to use any more plugins.

    Actually I was thinking about using the wp_list_pages function and explicitly pass the id(s) for the pages I need. The question is if this is possible using a hook element from you or do I need to revert to inserting this directly into the footer.php?

    I know it’s not possible to hook directly into the content since there are nothing to hook on to, so what do I do? This means I’m back to square one… Please, how can I solve this?

    #2223435
    David
    Staff
    Customer Support

    The alternative is to use a Block Element to build your Footers.

    https://docs.generatepress.com/article/block-element-site-footer/

    You can then create one for Logged in user and one for Logged out user.
    This will work if you can add static links for each of the menu items

    Note if you use GenerateBlocks to build the footers, you will need to set its Dynamic CSS to Inline in Dashboard > GenerateBlocks > Settings.

    #2225237
    Sebastian

    It turns out I went oldschool instead with a custom footer.php file. I’m not smart enough for getting things to work the way I intended it to by using blocks :).

    Thanks anyway.

    #2225252
    David
    Staff
    Customer Support

    🙂 Glad to hear you have a solution!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.