I have a page (Search) in WordPress, and I want to change title and meta description for this page dynamically, because this page will show posts dynamically by search term that uses have interred. I have no idea how I should do that. because I want it for a specific page only and not all pages or posts. I'd appreciate if someone helps me with this. it is important for me to solve it! I have searched and find something at this link but I don't know how should I find and call the search page. I write this, it is very basic:
function changetitle(){
//get some data for title
if($_GET['_sft_category'])
$mycategory= str_replace('-', ' ',$_GET['_sft_category']);
if($_GET['_sft_location'])
$mylocation=str_replace('-', ' ', $_GET['_sft_location']);
if ( is_page(548)) {
$title = $mycategory.$mylocation.' | site name ';
}
return $title;
}
add_action( 'wp_title', 'changetitle',10,3);
///change meta description
function changeMeta(){
if ( is_page(548)) {
$metadescription = 'some content';
}
return $metadescription;
}
add_action( 'wp_head', 'changeMeta');
I solved the problem, I write my solution maybe useful for others.
since I hadn't <title><?php wp_title(); ?>
at my header.php, I inserted that to the file and then my custom title added to the page. for removing duplicated title tag I used remove_action( 'wp_head', '_wp_render_title_tag', 1 );
for meta description also I used meta tag at header.php
but my problem is that it show meta description after some script files. is there a way to show it after title tag?