I am using shortcode and in that I want to change the title by setting the value from the database using custom tables.I have tried using the_title filter as follows
add_filter('the_title','set_page_title', 10, 2);
function set_page_title($title, $id){
if(in_the_loop()) {
return 'sdfdsfdsf';
}
return $title;
}
But my problem is I want to change this only on a specific page not all page.
This is my shortcode callback function
function bmg_company_detail_shortcode($args, $content) {
global $wpdb;
$table_name = $wpdb->prefix . 'bmg_company';
$company_id = $_GET['id'];
$output = '';
$result = $wpdb->get_results($wpdb->prepare("SELECT id,maincategoryid,name,website,yearfounded,supportpageurl,contactpage,country,about, isactive,contact_name,contact_email,contact_phone,support_phone,open_times,support_email, username, password from $table_name where id=%s", $company_id));
if($result) {
foreach($result as $row) {
set_page_title('',$row->name);
$output = '
<h3 class="bmg-company-title">'. $row->name .'</h3>
';
}
}
return $output;
}
I want to send the parameter to the function set_page_title but that doesn't work. I want this to happen only on page called company.