Parse error: syntax error, unexpected identifier "name", expecting ")"

Hi!
I am a newbie programmer.
I have this error: Parse error: syntax error, unexpected identifier “name”, expecting “)” in VSCode.
So I tried to fix this with ChatGPT many times, but ChatGPT could not find or fix the error.

// Display the greeting card

/**
 * Plugin Name: Greeting Cards
 * Plugin URI: 
 * Description: A WordPress plugin for creating and sharing electronic greeting cards.
 * Version: 1.0.0
 * Author: Your Name
 * Author URI: 
 * License: GPL-2.0+
 * License URI: 
 */

 // Register the greeting card custom post type
function register_greeting_card_post_type() {
    $labels = array(
        'name'               => _x( 'Greeting Cards', 'post type general name', 'greeting-cards' ),
        'singular_name'      => _x( 'Greeting Card', 'post type singular name', 'greeting-cards' ),
        'menu_name'          => _x( 'Greeting Cards', 'admin menu', 'greeting-cards' ),
        'name_admin_bar'     => _x( 'Greeting Card', 'add new on admin bar', 'greeting-cards' ),
        'add_new'            => _x( 'Add New', 'greeting_card', 'greeting-cards' ),
        'add_new_item'       => __( 'Add New Greeting Card', 'greeting-cards' ),
        'new_item'           => __( 'New Greeting Card', 'greeting-cards' ),
        'edit_item'          => __( 'Edit Greeting Card', 'greeting-cards' ),
        'view_item'          => __( 'View Greeting Card', 'greeting-cards' ),
        'all_items'          => __( 'All Greeting Cards', 'greeting-cards' ),
        'search_items'       => __( 'Search Greeting Cards', 'greeting-cards' ),
        'parent_item_colon'  => __( 'Parent Greeting Cards:', 'greeting-cards' ),
        'not_found'          => __( 'No greeting cards found.', 'greeting-cards' ),
        'not_found_in_trash' => __( 'No greeting cards found in Trash.', 'greeting-cards' )
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __( 'A custom post type for greeting cards', 'greeting-cards' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'greeting-card' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor' )
    );

    register_post_type( 'greeting_card', $args );
}
add_action( 'init', 'register_greeting_card_post_type' );

// Add a shortcode for displaying the greeting card form
function greeting_card_shortcode() {
    ob_start();
    ?>
    <form id="greeting-card-form" method="post">
        <label for="recipient-name">Recipient Name:</label>
        <input type="text" id="recipient-name" name="recipient_name"><br>

        <label for="sender-name">Your Name:</label>
        <input type="text" id="sender-name" name="sender_name"><br>

        <label for="message">Message:</label>
        <textarea id="message" name="message"></textarea><br>

        <input type="submit" value="Send">
    </form>
    <?php
    return ob_get_clean();
}
add_shortcode( 'greeting_card_form', 'greeting_card_shortcode' );

How to fix this error?
Thank you.

1 Like

As a newbie programmer, here are some steps to fix this issue:

  • Check for Missing Parenthesis: Look at the line of code mentioned in the error message and see if there’s a missing closing parenthesis ).
    IndentationError: expected an indented block error occurs when the code is not indented correctly.
  • Examine Function Calls: If name is part of a function call, ensure all arguments are correctly enclosed within parentheses.
  • Syntax Highlighting: Use the syntax highlighting in VSCode to identify parts of your code that might not be correctly formatted.
1 Like