I wrote a code and added to my functions.php on my WordPress site. Theme is a coupon theme.

If offer URL is filled, it shows a "go to offer" button; if not filled, it doesn't show.

Also there is a brand of offer; brand has a general homepage URL.

I want to assign brand URL to offer URL when offer URL is blank.

I wrote a code, and too see if it's working, i added shortcode. it shows the brand URL with shortcode correctly but button doesn't show. I couldn't find where the problem is? Please help.

i didn't add if's yet, need to see works for all then i will add "if offer url is blank" later.

  • rehub_offer_product_url is offer url of the offer.
  • dealstore is brand of the offer.
  • brand_url is a column of brand that has the URL.


if i fill rehub_offer_product_url it shows the button


added text + shortcode for testing to description

print of description


    add_filter('rh_no_brand_url', 'emreboslinkyonlendir',1000, 2);

    function emreboslinkyonlendir($offurl, $postid=''){
            $postaid = $postid;
            $postaid = get_the_ID(); //get id of opened post

            $offurl = get_post_meta($postaid, 'rehub_offer_product_url', true);
            $termaids =  wp_get_post_terms($postaid, 'dealstore', array("fields" => "ids")); //find brand of the post
            $termaid = $termaids[0];  //find first of array       
            $brandurl = get_term_meta( $termaid, 'brand_url', true ); //get brand_url column
            $offurl = esc_url($brandurl);
            //$offer_url = ( $brandurl );
        return $offurl;

   add_shortcode( 'offurl' , 'emreboslinkyonlendir' ); //for testing, to see i added a shortcode if it's working
  • i added update_post_meta( $postaid, 'rehub_offer_product_url', $brandurl, ' ' ); and STILL NOT WORKING. Please help. – emretosunkaya Sep 9 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.