intellipress_generator_content_tones

2 minutes, 6 seconds

Step 1: Understanding the Function
The intellipress_generator_content_tones() function is a helper function that returns an array of content tones. It currently includes various predefined tones such as ‘Authoritative’, ‘Clinical’, ‘Cold’, and more. The function uses the apply_filters() function to allow other developers to modify the array of content tones.

Step 2: Hook into the Filter
To customize the content tones, you can hook into the intellipress_generator_content_tones filter using the add_filter() function. This filter allows you to modify the array of tones before it is returned by the intellipress_generator_content_tones() function.

Here’s an example of how you can hook into the filter and add your own content tone:

function my_custom_content_tones( $tones ) {
    // Add your custom content tone
    $tones[] = esc_attr__( 'Custom tone', 'intellipress' );

    return $tones;
}
add_filter( 'intellipress_generator_content_tones', 'my_custom_content_tones' );

In the above code, we define a new function called my_custom_content_tones() that takes the $tones array as a parameter. Inside the function, we use the array push syntax ([]) to add our custom content tone called ‘Custom tone’ to the array. Finally, we return the modified array.

Step 3: Customize and Extend
You can further customize and extend the intellipress_generator_content_tones() function by adding more content tones or modifying existing ones. Simply use the array push syntax ([]) to add new tones or modify existing ones.

Here’s an example of how you can add multiple custom content tones:

function my_custom_content_tones( $tones ) {
    // Add your custom content tones
    $tones[] = esc_attr__( 'Custom tone 1', 'intellipress' );
    $tones[] = esc_attr__( 'Custom tone 2', 'intellipress' );

    return $tones;
}
add_filter( 'intellipress_generator_content_tones', 'my_custom_content_tones' );

In the above code, we added two custom content tones called ‘Custom tone 1’ and ‘Custom tone 2’ to the array.

Step 4: Enjoy the Customization
After adding the custom code to your project, you can use the intellipress_generator_content_tones() function to retrieve the modified array of content tones. The function will now include the default tones along with any custom tones you added.

$content_tones = intellipress_generator_content_tones();

foreach ( $content_tones as $tone ) {
    echo $tone . '<br>';
}

In the above example, we retrieve the content tones using the intellipress_generator_content_tones() function and then loop through the array to display each tone. Feel free to adapt this code to suit your specific needs.

And there you have it! You now know how to customize the intellipress_generator_content_tones() function to include your own content tones.

Was this article helpful?

In: