The insert_with_markers_inline_instructions WordPress PHP Filter allows you to modify the inline instructions inserted before the dynamically generated content.
Table of contents
Usage
add_filter('insert_with_markers_inline_instructions', 'your_custom_function', 10, 2);
function your_custom_function($instructions, $marker) {
// your custom code here
return $instructions;
}
Parameters
$instructions(array): An array of strings with inline instructions.$marker(string): The marker being inserted.
More information
See WordPress Developer Resources: insert_with_markers_inline_instructions
Examples
Add a custom instruction
Add a custom instruction to the inline instructions:
add_filter('insert_with_markers_inline_instructions', 'add_custom_instruction', 10, 2);
function add_custom_instruction($instructions, $marker) {
$instructions[] = 'Custom Instruction: This is a custom instruction';
return $instructions;
}
Remove a specific instruction
Remove a specific instruction from the inline instructions:
add_filter('insert_with_markers_inline_instructions', 'remove_specific_instruction', 10, 2);
function remove_specific_instruction($instructions, $marker) {
$instruction_to_remove = 'Instruction to remove';
if (($key = array_search($instruction_to_remove, $instructions)) !== false) {
unset($instructions[$key]);
}
return $instructions;
}
Clear all instructions
Clear all inline instructions:
add_filter('insert_with_markers_inline_instructions', 'clear_all_instructions', 10, 2);
function clear_all_instructions($instructions, $marker) {
return array();
}
Modify a specific instruction
Modify a specific instruction:
add_filter('insert_with_markers_inline_instructions', 'modify_specific_instruction', 10, 2);
function modify_specific_instruction($instructions, $marker) {
$search_instruction = 'Original Instruction';
$new_instruction = 'Modified Instruction';
if (($key = array_search($search_instruction, $instructions)) !== false) {
$instructions[$key] = $new_instruction;
}
return $instructions;
}
Add instructions based on marker
Add different instructions based on the marker:
add_filter('insert_with_markers_inline_instructions', 'add_instructions_based_on_marker', 10, 2);
function add_instructions_based_on_marker($instructions, $marker) {
if ($marker === 'MARKER_A') {
$instructions[] = 'Instruction for Marker A';
} elseif ($marker === 'MARKER_B') {
$instructions[] = 'Instruction for Marker B';
}
return $instructions;
}