Support » Fixing WordPress » template_redirect question

  • Resolved Smrth


    so, i have this one question about one function that use template_redirect action hook.. for example i’ll use this url
    that page/post don’t exist, and i would like to skip that step.. i have image in my head, but dont know how to write it..

    when requested url at end has portfolio redirect to template portfolio.php an archive template

    can someone help? thanks in advance..

    p.s. portfolio is custom post type…

Viewing 1 replies (of 1 total)
  • function portfolio_template_redirect() {
    		$url = $_SERVER['REQUEST_URI'];
    		$url = preg_match('/portfolio/', $url, $matches);
    		if($url) {
    	add_action('template_redirect', 'portfolio_template_redirect');

    no need.. here it is….

    here’s if you link to single portfolio is portfolio/something/

    `function portfolio_template_redirect() {
    $url = $_SERVER[‘REQUEST_URI’];
    $url = substr($url, -10);
    if($url == ‘portfolio/’) {
    $url = substr($url, 0, 9);
    } elseif($url == ‘/portfolio’) {
    $url = substr($url, 1, 10);
    if($url == ‘portfolio’) {

    add_action(‘template_redirect’, ‘portfolio_template_redirect’);`

Viewing 1 replies (of 1 total)
  • The topic ‘template_redirect question’ is closed to new replies.