Bird
Raised Fist0
Wordpressframework~20 mins

Block development basics in Wordpress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
WordPress Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this block's save function?

Consider this simple WordPress block save function:

export function save() {
  return (
    <p>Hello, Gutenberg!</p>
  );
}

What will this block render on the front end?

Wordpress
export function save() {
  return (
    <p>Hello, Gutenberg!</p>
  );
}
ANothing will render because save returns JSX
BAn empty div element
CA heading with the text 'Hello, Gutenberg!'
DA paragraph with the text 'Hello, Gutenberg!'
Attempts:
2 left
💡 Hint

The save function defines what HTML the block outputs on the page.

📝 Syntax
intermediate
2:00remaining
Which option correctly registers a block with a title and icon?

Which of the following code snippets correctly registers a WordPress block with a title and icon?

AregisterBlockType('my-plugin/my-block', { title: 'My Block', icon: 'smiley-icon', edit: () => null, save: () => null });
BregisterBlockType('my-plugin/my-block', { name: 'My Block', icon: 'smiley', edit: () => null, save: () => null });
CregisterBlockType('my-plugin/my-block', { title: 'My Block', icon: 'smiley', edit: () => null, save: () => null });
DregisterBlockType('my-plugin/my-block', { title: 'My Block', icon: 123, edit: () => null, save: () => null });
Attempts:
2 left
💡 Hint

The block registration requires a title string and an icon string matching Dashicons or SVG.

❓ state_output
advanced
2:00remaining
What will be displayed after typing in this block's input?

Given this edit function for a block:

import { useState } from '@wordpress/element';

export function Edit() {
  const [text, setText] = useState('');
  return (
    <input
      type="text"
      value={text}
      onChange={e => setText(e.target.value)}
      aria-label="Type something"
    />
  );
}

What will the user see as they type?

Wordpress
import { useState } from '@wordpress/element';

export function Edit() {
  const [text, setText] = useState('');
  return (
    <input
      type="text"
      value={text}
      onChange={e => setText(e.target.value)}
      aria-label="Type something"
    />
  );
}
AThe input box stays empty no matter what is typed.
BThe input box updates to show exactly what the user types.
CThe input box shows the reversed text of what is typed.
DThe input box throws an error and does not render.
Attempts:
2 left
💡 Hint

The useState hook stores the input value and updates it on change.

🔧 Debug
advanced
2:00remaining
Why does this block fail to save content?

Look at this block's save function:

export function save() {
  return (
    <div>
      <p>Saved content</p>
    </div>
  )
}

When used, the block does not save or display content on the front end. What is the problem?

Wordpress
export function save() {
  return (
    <div>
      <p>Saved content</p>
    </div>
  );
}
AMissing semicolon after return statement causes syntax error.
BThe save function must return a single root element, but it returns multiple.
CThe save function is missing a return statement keyword.
DThe save function is missing a closing semicolon after the return parentheses.
Attempts:
2 left
💡 Hint

Check for syntax errors in the save function's return statement.

🧠 Conceptual
expert
2:00remaining
Which statement best describes block attributes usage?

In WordPress block development, what is the main purpose of block attributes?

ATo store and manage block data that can be edited and saved, enabling dynamic content.
BTo define the block's CSS styles and layout only.
CTo register the block's name and icon for the editor interface.
DTo handle server-side rendering of the block content.
Attempts:
2 left
💡 Hint

Think about how blocks keep track of user input and settings.

Practice

(1/5)
1. What is the main purpose of creating blocks in WordPress block development?
easy
A. To create reusable content pieces that users can add visually
B. To write PHP code for custom themes
C. To manage user roles and permissions
D. To optimize database queries

Solution

  1. Step 1: Understand the role of blocks in WordPress

    Blocks are designed to let users add content pieces easily without coding each time.
  2. Step 2: Identify the main benefit of blocks

    Blocks are reusable and visually manageable content units improving editing experience.
  3. Final Answer:

    To create reusable content pieces that users can add visually -> Option A
  4. Quick Check:

    Blocks = reusable visual content [OK]
Hint: Blocks are for reusable visual content pieces [OK]
Common Mistakes:
  • Confusing blocks with PHP theme coding
  • Thinking blocks manage users or database
  • Assuming blocks are only for styling
2. Which function is used to register a new block type in WordPress block development?
easy
A. createBlockType()
B. initBlock()
C. addBlock()
D. registerBlockType()

Solution

  1. Step 1: Recall the standard WordPress block registration function

    The official function to register blocks is registerBlockType.
  2. Step 2: Verify other options are incorrect

    Functions like createBlockType, addBlock, and initBlock do not exist in WordPress block API.
  3. Final Answer:

    registerBlockType() -> Option D
  4. Quick Check:

    Register blocks = registerBlockType() [OK]
Hint: Remember: registerBlockType() registers blocks [OK]
Common Mistakes:
  • Using createBlockType() which is not a WordPress function
  • Confusing with addBlock() or initBlock() which don't exist
  • Misspelling the function name
3. Given this block registration code snippet, what will the block display in the editor?
registerBlockType('myplugin/example', {
  edit: () => {
    return 

Hello, WordPress!

; }, save: () => { return

Hello, WordPress!

; } });
medium
A. A paragraph with text 'Hello, WordPress!' in both editor and saved content
B. An empty block with no content
C. A syntax error preventing block registration
D. A block showing 'edit' text only

Solution

  1. Step 1: Analyze the edit function output

    The edit function returns a paragraph with 'Hello, WordPress!' which shows in the editor.
  2. Step 2: Analyze the save function output

    The save function returns the same paragraph, so saved content also shows 'Hello, WordPress!'.
  3. Final Answer:

    A paragraph with text 'Hello, WordPress!' in both editor and saved content -> Option A
  4. Quick Check:

    Edit and save return same paragraph = A paragraph with text 'Hello, WordPress!' in both editor and saved content [OK]
Hint: Edit and save return same JSX content means same display [OK]
Common Mistakes:
  • Thinking edit content differs from saved content
  • Assuming syntax error due to JSX
  • Confusing block output with empty or error
4. Identify the error in this block registration code:
registerBlockType('myplugin/test', {
  edit: () => {
    return 
Test Block
; }, save: () => { return div>Test Block; } });
medium
A. edit function missing return statement
B. Missing opening < in save function JSX
C. registerBlockType function name is incorrect
D. Block name 'myplugin/test' is invalid

Solution

  1. Step 1: Check the save function JSX syntax

    The save function returns div>Test Block; which is missing the opening < for the div tag.
  2. Step 2: Verify other parts are correct

    The edit function correctly returns JSX with <div>, the function name is correct, and block name format is valid.
  3. Final Answer:

    Missing opening < in save function JSX -> Option B
  4. Quick Check:

    JSX tags must start with < [OK]
Hint: Check JSX tags start with < and end with > [OK]
Common Mistakes:
  • Ignoring missing < in JSX tags
  • Thinking function names or block names are wrong
  • Overlooking return statements
5. You want to create a block that shows a dynamic greeting with a user name passed as an attribute. Which approach correctly uses attributes in block development?
hard
A. Hardcode the user name inside the save function JSX
B. Use a global variable for the name inside edit and save functions
C. Define attributes in registerBlockType and use props.attributes.name in edit and save
D. Only define attributes in edit function, ignore save function

Solution

  1. Step 1: Understand attribute usage in blocks

    Attributes must be declared in registerBlockType and accessed via props.attributes in both edit and save functions.
  2. Step 2: Evaluate other options

    Using global variables or hardcoding breaks reusability and dynamic behavior; ignoring attributes in save causes data loss.
  3. Final Answer:

    Define attributes in registerBlockType and use props.attributes.name in edit and save -> Option C
  4. Quick Check:

    Attributes declared and used properly = Define attributes in registerBlockType and use props.attributes.name in edit and save [OK]
Hint: Declare and use attributes via props in edit and save [OK]
Common Mistakes:
  • Using global variables instead of attributes
  • Hardcoding values losing flexibility
  • Not using attributes in save function
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard