Filter Hooks
Secondary Title provides several filters that allow developers to hook into some of the plugin's functions and modify its workflow and output. To learn more about using filters in WordPress, please read the related article in the Codex.
Filters
get_secondary_title($secondary_title, $post_id, $prefix, $suffix)
the_secondary_title($secondary_title, $post_id, $prefix, $suffix)
These two filters change the output of the final secondary title for a post.
Parameters:
$secondary_title
(string): The unmodified secondary title of a post.$post_id
(int): Targeted post.$prefix
(string): Characters inserted before the secondary title.$suffix
(string): Characters inserted after the secondary title.
secondary_title_get_default_settings($default_settings)
Hooks into the end of the secondary_title_get_default_settings
function and modifies its output.
Parameters:
$default_settings
(array): Same elements as in the parent function.
secondary_title_shortcode($attributes)
Modifies the output of all secondary title shortcodes.
Parameters:
$attributes
(array): The two attributes.$post_id
(int): ID of the targeted post.$allow_html
(string):"true"
and"false"
(de)activate HTML rendering.
secondary_title_columns_in_post_types($active_post_types)
Sets the post types where the secondary title column should be displayed.
Parameters:
$active_post_types
(array): Allowed post types, i.e. "post", "page", ...
Examples
The following shows code snippets that make use of Secondary Title's filters.
Example 1: Changing the default setting value
With this filter, you can change what Secondary Title regards as default options. These options will be applied to any function that has not been set or changed by the user.
<?php
/**
* Changes the default setting value for "Title format".
*
* @param $original_default_settings
*
* @return array
*/
function filter_secondary_title_change_default_setting($original_default_settings) {
/** Naming variables to keep things clear */
$default_settings = $original_default_settings;
/** Defining the new title format */
$default_settings["secondary_title_title_format"] = "%title% (%secondary_title%)";
/** Return modified array back to the main function */
return (array)$default_settings;
}
add_filter("secondary_title_get_default_settings", "filter_secondary_title_change_default_setting");
Example 2: Hiding Secondary Title's column on post overview pages
This snippet prevents Secondary Title from building a separate column on overview pages for posts, pages and other custom post types. The unfiltered function expects an array filled with post types where the secondary title is allowed to be shown. Replacing it with an empty array()
does the trick.
<?php
/**
* Hides the secondary title columns on post overview pages
* of posts, pages, and custom post types.
*
* @param $active_post_types
*
* @return mixed
*/
function hide_secondary_title_posts_columns($active_post_types) {
return array(); // To show, return $active_post_types
}
add_filter("secondary_title_columns_in_post_types", "hide_secondary_title_posts_columns");