2 minutes, 7 seconds
Step 1: Understanding the Function
The
intellipress_generator_content_goals()
function is a helper function that returns an array of content goals.
It currently includes various predefined goals such as ‘Attracting new leads’, ‘Building thought leadership’, ‘Driving sales’, and more.
The function uses the
apply_filters()
function to allow other developers to modify the array of content goals.
Step 2: Hook into the Filter
To customize the content goals, you can hook into the
intellipress_generator_content_goals
filter using the
add_filter()
function. This filter allows you to modify the array of goals before it is returned by the
intellipress_generator_content_goals()
function.
Here’s an example of how you can hook into the filter and add your own content goal:
function my_custom_content_goals( $goals ) {
// Add your custom content goal
$goals[] = esc_attr__( 'Custom goal', 'intellipress' );
return $goals;
}
add_filter( 'intellipress_generator_content_goals', 'my_custom_content_goals' );
In the above code, we define a new function called
my_custom_content_goals()
that takes the
$goals
array as a parameter. Inside the function, we use the array push syntax (
[]
) to add our custom content goal called ‘Custom goal’ to the array. Finally, we return the modified array.
Step 3: Customize and Extend
You can further customize and extend the
intellipress_generator_content_goals()
function by adding more content goals or modifying existing ones. Simply use the array push syntax (
[]
) to add new goals or modify existing ones.
Here’s an example of how you can add multiple custom content goals:
function my_custom_content_goals( $goals ) {
// Add your custom content goals
$goals[] = esc_attr__( 'Custom goal 1', 'intellipress' );
$goals[] = esc_attr__( 'Custom goal 2', 'intellipress' );
return $goals;
}
add_filter( 'intellipress_generator_content_goals', 'my_custom_content_goals' );
In the above code, we added two custom content goals called ‘Custom goal 1’ and ‘Custom goal 2’ to the array.
Step 4: Enjoy the Customization
After adding the custom code to your project, you can use the
intellipress_generator_content_goals()
function to retrieve the modified array of content goals. The function will now include the default goals and any custom goals you added.
$content_goals = intellipress_generator_content_goals();
foreach ( $content_goals as $goal ) {
echo $goal . '<br>';
}
In the above example, we retrieve the content goals using the
intellipress_generator_content_goals()
function and then loop through the array to display each goal. 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_goals()
function to include your own content goals.