• Resolved anjx

    (@anjx)


    Hi,
    I want put a custom page title in a specific page. So, if I’ll put a code in functions.php this works fine, but if I’ll put this code in my plugin, not works.

    The code is:

    function wp_myplugin_property_title()
    {
    	if( is_page('images') ){
    		$seotitle = 'custom title';
    		return $seotitle;
    	}
    }
    
    add_filter('wp_title', wp_myplugin_property_title, 100);

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter anjx

    (@anjx)

    Maybe I’m wrong position in the code .. I keep you updated ??

    You have to pass in the title and always return one. Using your conditional, you can then change the title to what you want on the indicated page:

    function myplugin_property_title($title)
    {
    	if( is_page('images') ){
    		$title = 'custom title';
    		return $title;
    	}
    
    	return $title;
    }
    
    add_filter('wp_title', myplugin_property_title, 10, 1);

    As a side note, you should avoid prefixing functions with wp_, because that’s what WordPress uses. It will prevent any confusion between custom functions and WordPress functions.

    Thread Starter anjx

    (@anjx)

    Found solution, I have put the code in the header.php file, before <title>.
    Thanks Ryan.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function to change page title not works in plugin’ is closed to new replies.