• Resolved glepage

    (@glepage)


    Hi, I am making my site look like an Application by removing the Safari Toolbars on all apple devices. In order to do this I all links need to target=”_webapp” on the entire wordpress site. I am trying to create a function to do this from some code I grabbed that was creating a target=”_blank” but was for external links only, throughout the website.

    Can someone PLEASE assist me with modifying this function to go into my ‘functions.php’ folder.

    Or if someone knows of a better method that would be great.
    Thanks.

    Code:
    function autowebapp($text) {
    $return = str_replace(‘<a href = ‘, ‘<a target = “webapp” href = ‘, $text);
    $return = str_replace(‘<a target = “webapp” href = “https://www.mydomain.com&#8217;, ‘<a href = “https://www.mydomain.com&#8217;, $return);
    $return = str_replace(‘<a target = “webapp” href = “#’, ‘<a href = “#’, $return);
    $return = str_replace(‘ target = “webapp”>’, ‘>’, $return);
    return $return;
    }
    add_filter(‘the_content’, ‘autowebapp’);
    add_filter(‘comment_text’, ‘autowebapp’);

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    This sort of link manipulation came up for me before. *adjusts tin foil hat*

    The code you’ve posted will only update links in the post/page content as well as comments. Give this pastebin.com link a look.

    https://pastebin.com/SmW0wLCs

    1 – On the pastebin.com page, use the download link save the file add-webapp-to-links.php (remove the .txt extension).

    2 – Copy that file into your wp-content/plugins directory.

    3 – Activate the plugin called Add target="webapp" to links

    It doesn’t change any data, it just filters it. If anything goes wrong deactivate that plugin.

    It will harvest all of the links in the content and comments, modify them, and string replace them with the updated target="webapp" links.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Huh. It may be easier than that to add a target="webapp" to links.

    I’ve added this to that plugin code in the pastebin.com link.

    add_action( 'wp_head' , 'mh_base' );
    function mh_base() {
       echo '<base target="webapp" />';
    }
    Thread Starter glepage

    (@glepage)

    Wow! Thanks Jan.. Excellent code.. Almost there.

    I need to add a few filters I think..

    the_footer
    menus
    the_post
    the_excerpt
    the_header
    the_category
    the_sub_category

    I don’t think I have the right syntax. The reason for this is to allow wordpress sites to appear as mobile web apps and Hiding Safari User Interface Components.

    I suspect this will be a HIGHLY used plugin over the coming years..

    Thread Starter glepage

    (@glepage)

    I can’t seem to install the plugin..

    I get an error:

    Unpacking the package…

    Installing the plugin…

    Warning: Invalid argument supplied for foreach() in /vservers/SERVERUSERNAME/htdocs/wp-admin/includes/class-wp-upgrader.php on line 556
    The package could not be installed. No valid plugins were found.

    Plugin install failed.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    It’s not a zip file, just text.

    Try downloading and rename it to add-webapp-to-links.php. Then zip that into a zip fle archive.

    Then upload that new zip file archive to WordPress via the dashboard.

    Thread Starter glepage

    (@glepage)

    Should there be a closing PHP tag at the end of the code you put in the pastebin?

    Thread Starter glepage

    (@glepage)

    Successful install!!! ??

    Thank Jan.

    Now to get the plugin to function for pages, categories and posts. If any of the internal links does not contain ‘target=”webapp”‘ then the website app takes the user to back to safari. This is the main reason for using the plugin.

    Cheers.
    G

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add a target=”_webapp” to all links on wordpress’ is closed to new replies.