0

I have created a shortcode functions to display the state name in the content. I have created one page specially to display the state names into the content.

I have this line on my page - Why Providers from [state name shortcodes] choose our company? I have added the shortcode functions and it is working fine. when visitor from any of the U.S states will entry my page it will show state name on shortcodes.

What i need is:

When they visit my original page, it need to show like this Why Providers choose our company?

I need any suggestion to not to display the text "from"

And I have some more functions to display state code & state plan. Below function I have need to use. This will show only the state name. I used JSON array to show the state details.

 add_shortcode('US_STATE_NAME_WITH_TEXT',
 'mp_usstate_name_with_text');

 function mp_usstate_name_with_text() {

        $usstate_name = "";
        $chosen_state = [];
        global $STATES_ARRAY;
        //$states = json_encode(STATES_ARRAY);
        //alert("Value of States Array" + $STATES_ARRAY);
        //$state = $states.find(state => state.slugCode === get_query_var("usstate"));
        $state = array_filter($STATES_ARRAY, function($state) {
            return $state["slugCode"] === get_query_var("usstate");
        });

       if(count($state) > 0){
        $chosen_state = array_pop($state);
        if(!empty($chosen_state) ){ 
            $usstate_name = $chosen_state["name"]; 
        }
      }
        return .$usstate_name;
    }

1 Answer 1

1

I think you can add "from" to return value of shortcode function.

return 'from ' . $usstate_name;

From

Why Providers from [state name shortcodes] choose our company?

to

Why Providers [state name shortcodes] choose our company? 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.