Support » Developing with WordPress » How to make a conditional homepage button telephone or hyperlink

  • Website has Genesis Framework theme: Showcase Pro

    I have a button on my homepage background image that links to another page on the site. Is it possible to make that button conditional so if it is displayed on a mobile device the link when clicked calls a phone number and when it is not links to another page on the site?

    Your help is appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    You could code it using the wp_is_mobile() test

    https://codex.wordpress.org/Function_Reference/wp_is_mobile

    I’d probably write a shortcode and use it like:

    [my-link mobile=”tel:123-456-78900″ else=”http://mysite.com/page”]text[/my-link]

    or something like that.

    @sterndata,

    Thanks for the quick reply!

    I am new to WP so appreciate the help getting me up to speed on this. So if I understand you correctly if I have the code for the button on the homepage (in a text box) as:

    <a href="//mysite.com/about" class="button small arrow-right">Lets Talk</a>

    Then I would replace it with what you wrote and it would be like this:

    <a href="[my-link mobile=”tel:123-456-78900″ else=”http://mysite.com/page”]text[/about]" class="button small arrow-right">Lets Talk</a>

    Of course I would have to figure out how to write the shortcode “my-link” and where to place it.

    Did I understand you correctly?

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    sorta 🙂

    You’d probably want to tweak the shortcode to allow you to set class paramters, etc.

    The shortcode itself would create the whole string, not be dropped into the middle of it.

    Here’s what you need to know about writing a shortcode:

    https://codex.wordpress.org/Shortcode_API

    @sterndata

    Thanks for the info, that gives me more than enough to start learning how to put this together.

    Off to Youtube for a “How to create shortcodes” marathon!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to make a conditional homepage button telephone or hyperlink’ is closed to new replies.