Category: Uncategorized

  • Nav Bar modification on Scroll

    1 Set up nav bar block.

    Add your links and ensure it has a parent container (like a Group Block or Header Block) so you can apply styles to it.

    2 Custom CSS

    You can use the Additional CSS section in the WordPress Customizer or enqueue a custom CSS file. Here’s the CSS:

    3 The JS

    You need to enqueue a small JavaScript file in your theme or use a plugin like Code Snippets to inject this code.

    Here’s the JavaScript:

    4 Assign shrinkable-nav bar class

    In the Block Editor:

    1. Select the parent container block for your menu (Group or Header block).
    2. In the Block Settings, under Advanced, add shrinkable-navbar as an additional CSS class.

    5 Enque js

    If you’re using a child theme, you can enqueue the JavaScript in your theme’s functions.php file:

    Create the shrink-navbar.js file in the /js/ folder of your theme and add your JavaScript there.

    6 In line JS

    Messy but maybe works

    Adding <script> tags in a Custom HTML block might not work if WordPress blocks them for security reasons. If this happens, try the other methods above.

    Inline JavaScript in content blocks is generally discouraged because it can make maintaining your code more difficult in the long run.

Categories