• Resolved jojas

    (@snowcap)


    In WordPress it’s possible to add a custom endpoint to pages, such as: https://example.com/example/test where test is the custom endpoint.

    
    function myEndpoint_init() {
      $myEndpoint = "test";
      add_rewrite_endpoint( $myEndpoint , EP_ALL );
    }
    add_action( 'init', 'myEndpoint_init',11);

    If you then hook into template_redirect you can detect if there’s an endpoint and do something custom accordingly… such as:

    function myCustomCode()
    {
      //do stuff
      echo "the page id: " . get_the_ID();
    }
    add_action('template_redirect', 'myCustomCode');

    This works great on every page, except for the home page, which doesn’t work as expected.

    Example output for https://example.com/example/test: the page id: 57 (this is correct)

    For https://example.com/example/: the page id: 57 (this is correct)

    For https://example.com/: the page id: 5 (this is correct)

    For https://example.com/test the page id: 1 (this is not correct)

    And it also does not print the correct page.

    What am I missing? How would I achieve this?

Viewing 1 replies (of 1 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @snowcap Unless it’s spam, abuse or something broken in the forums please do not report topics again.

    It is not a means to get faster support, it only gets forum moderators attention and no one else.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I add a custom endpoint to the home page in WordPress?’ is closed to new replies.