intellipress_generator_content_types

2 minutes, 6 seconds

Step 1: Understanding the Function
The intellipress_generator_content_types() function is a helper function that returns an array of content types. It currently includes various predefined types such as ‘Article’, ‘Blog post’, ‘Case study’, and more. The function uses the apply_filters() function to allow other developers to modify the array of content types.

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

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

function my_custom_content_types( $types ) {
    // Add your custom content type
    $types[] = esc_attr__( 'Custom content', 'intellipress' );

    return $types;
}
add_filter( 'intellipress_generator_content_types', 'my_custom_content_types' );

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

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

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

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

    return $types;
}
add_filter( 'intellipress_generator_content_types', 'my_custom_content_types' );

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

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

$content_types = intellipress_generator_content_types();

foreach ( $content_types as $type ) {
    echo $type . '<br>';
}

In the above example, we retrieve the content types using the intellipress_generator_content_types() function and then loop through the array to display each type. 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_types() function to include your own content types.

Was this article helpful?

In: