是否可以定义短代码,然后在模板文件中加密 - Wordpress

I have a file a.php where I have defined <a href="abc.com/page_id=11?key=123">link</a>

I have created a custom template custom.php and created a page at wordpress backend that has page_id=11

So, from a.php I am sending a user to custom.php with the help of page_id and then fetching the key=123

This is working fine..

The only problem is that I am not sure about page_id = 11.

Is it possible to get the same using the shortcode so as I can avoid using the page_id in my template file.

Function to create a shortcode to get the page id

function id_shortcode( $atts ) {
    // extract the variables, if there is no ID attr, the default is 1
    extract( shortcode_atts( array(
        'id' => 1
    ), $atts ) );
    // set page id to either the id attr which defaults to one.
    $page_id = $id;
    $page_data = get_page( $page_id );
    return 
}
// shortcode registration
add_shortcode( 'getid', 'id_shortcode' );

Then you can simply use [getid] shortcode on your page to get that page id

I hope i have understood and solved your problem...

And you can call this shortcode also in your template file

<?php echo do_shortcode("[getid]"); ?>