Extracting URL from Shortcode
-
Posting this in case it’s helpful to someone else.
I found myself in a situation where I needed to extract the logout URL from the anchor tag returned from the [llrmlogout] shortcode. So, I created this quick function. Just modify to work with all the other shortcodes provided by this plugin.
// Function to extract the logout url from the login-logout-register-menu plugin shortcode function get_logout_url() { if ( !shortcode_exists( 'llrmlogout' ) ) { return; } $dom = new DOMDocument; $logout_html = do_shortcode( '[llrmlogout]' ); $dom->loadHTML($logout_html); $node = $dom->getElementsByTagName('a')->item(0); return $node->getAttribute( 'href' ); } add_shortcode('get-logout-url', 'get_logout_url');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Extracting URL from Shortcode’ is closed to new replies.