0
0
Wordpressframework~20 mins

Block development basics in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 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.