mardi 12 septembre 2017

How to catch a URL parameter and display a custom page title in wordpress

As a novice , I asked this to lots of paid developers who either said No or quoted exorbitant price or said Not achievable.

But I have achieved few thing on my site by going through all the interactions here. So thought of taking a second opinion.

A custom gateway payment plugin returns to Woocommerce Thank you page , if the transaction is successful but returns to a normal wordpress page -failed-payment, if payment is unsuccessful.

For the unsuccessful payment the return URL is :

http://ift.tt/2wZGueM.

On the failed-payment page, I want to display a personalised Page Title as Sorry, Jack, Your payment was unsuccessful.

Creating a new page template or modifying page template file is not an option. Has to be done via theme function.php.

To write the page title , I have thought of the following to be written in theme function.php :

   function assignPageTitle( $title ){
        if ( is_page(3062) ) {
          $title = sprintf("Sorry, %s, Your payment was unnsuccessful", b_name);
    }

    return $title;
    }
    add_filter('wp_title', 'assignPageTitle');

Is it achievable or impossible ? If achievable , how should I approach doing it??

Thanks.




Aucun commentaire:

Enregistrer un commentaire