M
M
MrSusua2015-11-27 08:19:43
WordPress
MrSusua, 2015-11-27 08:19:43

How to change page url in WordPress?

Good afternoon!
I can't write a function that changes the page name in WordPress from "page-name" to "alternate-page-name"...
Here's what I've done so far (doesn't work):

function true_add_html_on_pages() {
  global $wp_rewrite;
 
  if ( $wp_rewrite->get_page_permastruct() == 'page-name' ) {

    $wp_rewrite->page_structure = 'alternate-page-name';

    $wp_rewrite->flush_rules();
  }
}
 
add_action('init', 'true_add_html_on_pages', -1);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
litvin2, 2015-12-04
@litvin2

Tell the task in full: in what cases and why you need to change.
The solution you provided is a bit of an incomprehensible solution. Will be called each time the page is generated. The first time the name has changed, and then it will work in idle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question