Automatically redirect a page to a category that share the same slug

Well you can just turn the code 180 degrees from the linked question and problem solved. Just kidding. I would start with getting the current page slug, using that slug search for a category that has that slug, if found, redirect to it add_action(‘template_redirect’, ‘bt_redirect_page_to_category’); function bt_redirect_page_to_category () { // if we are not in … Read more

Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)

This is because you did not put singular.php in the URL, and if you did it wouldn’t make any sense. Remember, WordPress loads the template, not the other way round, your mental model of how this works is upside down. What’s going on? Why is singular.php the file being accessed while PHP prints that the … Read more

Special Character Appearing in my WordPress Pages Content

My guess is that you pasted something from a Windows environment and that’s the CR (carriage return, I think) character. I’d go into the editor and just remove those line breaks. That should fix the problem. Also, you might look into standardizing the content type meta tag. You’ve got <meta charset=”UTF-8″ /> I could be … Read more

How to add rel=”nofollow” to wp_list_pages?

use wordpress build in funcion for that “wp_rel_nofollow” with a hook to wp_list_pages. paste this code in your theme’s functions.php file and you are set. function add_no_follow($output){ return wp_rel_nofollow($output); } add_filter(‘wp_list_pages”https://wordpress.stackexchange.com/questions/7688/,”add_no_follow’); hope this helps.

Is it possible to add a child post into the parent page?

First, you need to query the child Pages: $pageargs = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID ); $childpages = get_posts( $pageargs ); Then, you need to create your custom Loop: foreach ( $childpages as $childpage ) { // Output whatever you want here, such as: … Read more

Include multiple page ids in loop

page is not an accepted parameter for WP_query , you can use page_id but that doesn’t accept an array , only one specific ID, so just use post__in like this: <?php $args = array( ‘post__in’ => array(139, 54) ); $loopy = new WP_Query($args); while ($loopy->have_posts()) : $loopy->the_post(); ?> <div class=”item”><?php the_title(); echo ‘<br ?>’; echo … Read more

check first and last child pages wordpress

You can use get_pages() function to do that: global $post; $current_page_id = $post->ID; //Sort by creation time: $args = array( ‘child_of’ => $current_page_id, ‘sort_order’ => ‘ASC’, ‘sort_column’ => ‘post_date’, ‘hierarchical’ => 1, ‘number’ => 1, ); $first_child = get_pages($args); //moddify args to get the last child: $args[‘sort_order’] = ‘DESC’; $last_child = get_pages($args); //when loopting thrugh … Read more