0

I have successfully changed the name of a specific page using this code in my functions.php file:

add_filter('pre_get_document_title', 'change_my_property_title');

function change_my_property_title($title) {
     if ( is_page('property') ) {
       return 'Property';
     }
     return $title;
}

My problem is I can't figure out how to change the name to an actual php variable that is on the property page. I am pulling property information from a json url and would like the address to be the title. If I try to point to the variable in my return statement nothing comes up.

Here is the page I'm working on: http://geekoutaustin.com/live/property/?id=d86967ad43c2f5271b02f94247ef858d&wpf28382_5=8252427

1
  • 1
    How are you defining this variable? Commented Aug 27, 2021 at 2:49

2 Answers 2

0

If your template is using the_title you can override it by adding this filter to your function

add_filter( 'the_title', 'change_my_property_title' );
2
  • I don't think that's the part OP needs help with.
    – Rup
    Commented Aug 27, 2021 at 15:36
  • ^ I can already change the name of the page to a specific string but I'm looking to make the page an actual variable that is found on the page itself. Putting a variable in the functions.php doesn't work. Commented Aug 28, 2021 at 17:31
0

I got it! By using the functions.php page I wasn't able to use variables defined on the page I wanted to create custom titles for. I ended up adding the below code to my custom page php.

<?php $newtitle = ucwords($mlsa->StreetNumber . ' '  . $mlsa->StreetName . ' ' . $mlsa->StreetSuffix.', '. $mlsa->City); ?>
<script>document.title = "<?php echo $newtitle; ?>";</script>

or a more simple version:

<?php $newtitle = $someVariable; ?>
<script>document.title = "<?php echo $newtitle; ?>";</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.