I have this function
function my_product_title($title, $id)
{
if(in_the_loop() && is_product())
{
return '<span class="border">FooBar</span>';
}
return $title;
}
add_filter( 'the_title', 'my_product_title', 5, 2);
and it can replace the product title with return '<span class="border">FooBar</span>';
.
I also have a custom script in “mycustomtitle.php” that can modify the products titles and my script can echo that modified title as $mycustomtitle
I want to replace the original product title with my $mycustomtitle
without changing anything in the core files.
I’ve tried to just change return '<span class="border">FooBar</span>';
to $mycustomtitle
but it only removes the original title and gives no output at all…
Thanks!
UPDATE 2016-10-20 With custom code:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/seo-controlpanel/seo-engine/explode.php';
$tit1 = $boomprint[array_rand($boomprint)].' '.file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/seo-controlpanel/write-to/product-title-h1.php');
$tit2 = $boomprint[array_rand($boomprint)].' '.file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/seo-controlpanel/write-to/product-title-h1.php');
$title_keys = array($tit1,$tit2);
$title_key11 = $title_keys[array_rand($title_keys)];
if(!function_exists(spin11)){
function spin11($string11) {
while(true) {
if(!preg_match_all('/({([^{]*?)})/', $string11, $matches))
break;
foreach($matches[2] as $i => $match) {
$parts = explode('|', $match);
$string11 = str_replace_once11($matches[0][$i], $parts[mt_rand(0, count($parts)-1)], $string11);
}
}
return $string11;
}
}
if(!function_exists(str_replace_once11)){
function str_replace_once11($from,$to,$str)
{
$str = explode($from,$str,2);
return $str[0].$to.$str[1];
}
$title_id11 = get_the_ID();
$fileLocation11 = getenv("DOCUMENT_ROOT") . '/wp-content/plugins/seo-controlpanel/seo-cache/product-title-h1/'.$title_id11.'.txt';
if(!file_exists($fileLocation11)){
$file11 = fopen($fileLocation11,"w");
$content11 = spin11($title_key11);
fwrite($file11,$content11);
fclose($file11);
}
if(file_exists($fileLocation11)){
$myFile11 = $fileLocation11;
$fh11 = fopen($myFile11, 'r');
$theData11 = fread($fh11, filesize($myFile11));
fclose($fh11);
}
}
?>
3
Answers
Is $mycustomtitle global variable or it is defined inside another function/method/class?
If it is global variable this may help:
Insert your custom code in your function.