C
C
Captain Cocoa2017-05-21 15:33:59
JavaScript
Captain Cocoa, 2017-05-21 15:33:59

How to add the /demo directory to a post?

Hello everyone, I have such a url structure on my site. сайт.ру/категория/название_записи
I have a demo for each post, and I would like to display it via a link сайт.ру/категория/название_записи/demo
. How can this be implemented in wordpress?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2017-05-21
@RadCor

Hello.
You can register a variable named demo

function dco_rewrite_endpoint() {
    add_rewrite_endpoint('demo', EP_PERMALINK);
}

add_action('init', 'dco_rewrite_endpoint');

And then check in the right place and perform the actions you need
global $wp_query;
if (isset($wp_query->query_vars['demo'])) {
    echo 'Это demo';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question