Home > database >  How can I make a button in wordpress theme redirect to a specific template onclick?
How can I make a button in wordpress theme redirect to a specific template onclick?

Time:04-14

So I have this code in php:

add_filter( 'template_include', 'my_callback' );


function my_callback( $original_template ) {
  if ( some_condition() ) {
    return SOME_PATH . '/some-custom-file.php';
  } else {
    return $original_template;
  }
}

and I want to re-write this code in order to use it inside an <a> element and specifically in an onclick="" attribute of that <a> element. All in all my main goal is to create 2 template files in my theme's folder where one is for most recent posts and the other is for the most popupal posts, and the use the code above but inside the <a> element to be able to redirect to each one respectively.

Any suggestions? Thanks in advance,
Jameu

CodePudding user response:

Create two wordpress native pages (inside WP Backend), use the template you want (create it) with each one. Here is the template pages doc:

TEMPLATE FILES

Once you have done it just link them with regular html: <a href="/page1">LINK PAGE1</a> or with javascript if you want

  • Related