Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#57908 closed defect (bug) (invalid)

No reference for hook "logout-link" in Documentation

Reported by: mlheyd's profile mlheyd Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Shortcodes Keywords:
Focuses: Cc:

Description

I am developer but new to WordPress. The following code added to a child theme functions.php file works perfectly to log a user out and redirect to the home page. I actually got the code from ChatGTP. I thought I would check the WP documentation to see how I missed the hook that worked but it turns out that I cannot find it anywhere.

The issue is that all the documentation uses wp_logout and iterations thereof but I could not get any of that to work. Here is the super simple code that works. The issue is, is it documented anywhere.

<?php

function logout_link_shortcode() {
    return '<a href="' . wp_logout_url( home_url() ) . '">Logout</a>';
}
add_shortcode( 'logout-link', 'logout_link_shortcode' );

Change History (1)

#1 @costdev
2 years ago

  • Component changed from General to Shortcodes
  • Keywords needs-user-docs removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 6.1.1 deleted

Hi @mlheyd, welcome to Trac!

In this context, logout-link is not a hook, but a shortcode tag, used like so: [logout-link]. This is a user-defined string, so you could, for example, have written add_shortcode( 'logout_link', 'logout_link_shortcode' );, and then used this with [logout_link] instead.

As this is a user-defined string, there's no documentation for logout-link specifically. However, you can view the documentation for add_shortcode, and read about the Shortcode API.

Hooks, on the other hand, refer to Actions and Filters. Learn WordPress has a tutorial on Actions and Filters that you might find very useful for finding out more about these.

Trac itself is for the development of WordPress Core, rather than for discussion and/or support. You can find out more from the resources on Learn WordPress, and you can also ask questions on the "Developing with WordPress" forum.

As this ticket doesn't report a bug, or request an enhancement or feature in WordPress Core, I'll close this ticket as invalid.

Have a great time developing with WordPress!

Note: See TracTickets for help on using tickets.