How to properly print a 404 error without redirecton? (i.e. keeping the current URL)

You should be using a filter outside of your template for this: add_filter( ‘template_include’, ‘wpa62226_template_include’, 1, 1 ); function wpa62226_template_include( $template ){ if( is_page( ‘some-page’ ) ) : global $wp_query; $wp_query->set_404(); status_header( 404 ); $template = locate_template( ‘404.php’ ); endif; return $template; } Your code is executed before the template is loaded, so it becomes … Read more

How do I Redirect a WordPress Page?

I’m sure there is a more elegant way of achieving your desires, however this method does work. Just tested it. /** * Redirect pages from array. * * @author Michael Ecklund * @author_url https://www.michaelbrentecklund.com/ * * @return void */ function redirect_pages() { // Page from => Page to $redirect_pages = array( ‘wordpresspage’ => ‘/wordpress-page’ ); … Read more

Different templates for same content, landing page from different URLs (generic, simple)

I don’t know what your definition of “simple” is, so not sure this qualifies. It’s not really a simple task to do this dynamically. First, we register a new query var to pass the alternate identifier: function wpd_portfolios_query_var($query_vars){ $query_vars[] = ‘portfolio_key’; return $query_vars; } add_filter(‘query_vars’, ‘wpd_portfolios_query_var’); Next, we add a rewrite rule to handle incoming … Read more

WordPress site URL changed; how to fix it without database access?

See Changing The Site URL « WordPress Codex for recovery instructions on how to reset the URLs without database access, i.e. by editing either the wp-config.php file or the theme’s functions.php file with FTP: 1) by adding lines to wp-config.php (which can be left in place): define(‘WP_HOME’,’http://example.com’); define(‘WP_SITEURL’,’http://example.com’); 2) or the theme’s functions.php file (but … Read more

Create Custom Post Type as page

You can make a custom template for a custom post type. Generally I use the single.php file and duplicate it. Then I rename it to single-{custom-post-type}.php as per Post Type Templates. In your case the template file should look like this single-uslugi.php. As far as saving the old URLs and fixing things I don’t quite … Read more

Get Top parent url

You have to do it in a loop: $p = $post; while ( $p->post_parent ) { $p = get_post( $p->post_parent ); } $parent_page_link = get_permalink( $p->ID ); Another way is to use get_ancestors function: $ancestors = get_ancestors( $post->ID, ‘page’, ‘post_type’ ); $root = ( ! empty( $ancestors ) ) ? end($ancestors) : $post->ID; $parent_page_link = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)