how to create shortcode in wordpress

So I have the following code:

 <span class="delete"><a onclick="return confirm('Are you sure?');" href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'my-delete-product', 'product_id' => $post->ID ), my_get_navigation_url('products') ), 'my-delete-product' ); ?>" rel="nofollow noreferrer noopener"><?php _e( '삭제', 'my' ); ?></a> | </span>

It is a simple button.

I want to make this into a shortcode so that I can use it anywhere where appropriate.

Any suggestions?

Thanks.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can create your short code just few steps.

function short_codeFunction_name( $atts, $content=null ) {
    shortcode_atts( array(), $atts);
    $rowin = '<div class="row">'.do_shortcode( $content ) .'</div>';
    return $rowin;
}
add_shortcode( "your_shortcode_name", "short_codeFunction_name" );
  1. Then you can access [your_shortcode]Here your
    content[your_shortcode]
    format inside the Post,page etc.
  2. add this function inside function.php in active theme directory.
  3. use inside your theme directory

Method 2

The WordPress API documents this very thoroughly. Check it out here.

And if you are feeling lazy, here is a custom generator.

If you have a specific question beyond that, comment below.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x