• Hello, I’ve been following a guide on how to make a blog from scratch. I copied a custom menu code into my functions.php that actually borked my plugin search function and media uploader.

    I am running a localhost with AMPPS

    If the code appear within my functions.php, then I can’t search for a plugin. It will keep on loading indefinitely. I also can’t delete an existing plugin while this error shows up

    Deletion failed: <!– Adding Custom Menu option –> Return to InpharmD Blog Exploring Evidence {“success”:true,”data”:{“delete”:”plugin”,”slug”:”robo-gallery”,”plugin”:”robo-gallery\/robogallery.php”,”pluginName”:”Robo Gallery”}}

    My media gallery will also not load the images it has. If I try to load a new image, this error message appears:

    An error occurred in the upload. Please try again later.

    Here is the code:

    <!-- Adding Custom Menu option -->
    <?php
    function wpb_custom_new_menu() {
    register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
    }
    add_action( 'init', 'wpb_custom_new_menu' );
    ?>
    
    <?php
    wp_nav_menu( array(
        'theme_location' => 'my-custom-menu',
        'container_class' => 'custom-menu-class' ) );
    ?>
    

    Is there something wrong with the code? I want to try and customize my own menu using code and without a plugin if possible. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • wp_nav_menu outputs the HTML for the menu and belongs in a template where you want the menu to appear. It’s going to wreak havoc if you put it in functions.php.

    Also make sure you’re not opening php tags (<?php) if they’re already open. I can’t tell if that’s the case based on your code, but if you just added what you’ve posted directly to the bottom of your functions file, then they will be and you’ll have issues caused by that.

    Thread Starter nicerice

    (@nicerice)

    You’re right. I did add <?php at the beginning because it didn’t work otherwise in functions.php.

    So if I want to do this properly, I need to place this code in one of the specific php files.

    However, besides functions.php, I’m not sure where I should be putting all these codes. I thought placing it in index.php would be best because that is considered the base file but it doesn’t show up? I tried placing them in various other phps like the header and single but it’s still not showing up. Could it be because I didn’t enqueue every php file? Right now, I only have the bootstrap template I used and the css file:

    // Add scripts and stylesheets
    function startwordpress_scripts() {
    	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '4.0.0' );
    	wp_enqueue_style( 'blog', get_template_directory_uri() . '/css/blog.css' );
    	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), '4.0.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'startwordpress_scripts' );

    Thanks you for any additional insight.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A function that adds custom menu option is preventing’ is closed to new replies.