I am brand new at writing WordPress plugins, so to start I am trying to create a simple one that just modifies a string. I wrote the script a while ago, and know that it functions. But to use it for WordPress I want to apply it to the post titles. When I replaced the string with the function “get_the_title()” it returns a white screen. I stripped it down to:
function display_title() {
echo get_the_title();
}
add_action('the_title', 'display_title');
This still returns a white screen. So I figure it must be the “get_the_title()” function. Can anybody explain to me why this doesn’t work, and maybe a different way to retrieve the title string?
As John says
the_titleis a filter rather than an action hook, although your function will be called regardless of whether you register it usingadd_filteroradd_action.Your problem is that with filters your function is expected to return a value (normally a modified version of the argument passed). So, to modify the title using this filter you should do something like this: