Alter existing page contents based on url

I belive this will work for you: Create a “page” called “stuff”, then create another page called “foo”, make it child of “stuff”, now stuff/foo will exist and won’t be 404. Finally use the_content filter and make the required data manipulation. The other choice (hard way) you’d have is to use pre_get_post hook, so you … Read more

Use content from one page in another template

Assuming you have the following pages: Home About us that has a slug of about-us And you want to display the content of the About us page into the Home page. <?php $about_us = get_page_by_path(‘about-us’); // supply the page slug; i.e. about-us $about_us_content = get_the_content($about_us->ID); ?> <div><?php echo $about_us_content ; ?></div> Alternatively, you can use … Read more

Changes in WordPress taking 48hrs to reflect [closed]

You have to check if your WordPress site is using a cache plugin (such as WP Super Cache) or a CDN like CloudFlare or Amazon CloudFront. In that case, you can manually clean the cache in order to see those changes. You can also force refresh without cache, that will make you be able to … Read more

Function to incorporate an option in each Page

It sounds like you need custom meta boxes. You could either create your own plugin to add them or use a plugin like Advanced Custom Fields. You would add two meta boxes to each post type where you want to be able to select these options, one to select the image, and another to set … Read more

how avoid the link of the current post in the menu in the sidebar?

you can try this code. the first filter is to customise the widget arguments and the second filter is in the menu generation. add_filter(“widget_nav_menu_args”, function ($nav_menu_args, $nav_menu, $args, $widget_instance) { $post = get_queried_object(); if (is_a($post, “WP_Post”)) { $nav_menu_args[“remove_post_in_widget”] = $post->ID; } return $nav_menu_args; }, 10, 4); add_filter(“wp_nav_menu_objects”, function ($sorted_menu_items, $args) { if (isset($args->remove_post_in_widget)) { foreach … Read more

How to store archived copies of a WordPress site

One option: revisions. If you save a large number of revisions for your pages, you can then browse through the revision history and “Preview” what a particular page looked like at a particular point in time. However, this requires whoever is viewing the past view to be logged in, since Previews are not public. Another … Read more

$_GET parametters not working in an specific template

WordPress is removing all unknown (not registered) $_GET parameters while processing the request (same is true for $_POST). You can either register the custom variable, or just go the canonical PHP way by using filter_input(). This will access the original, unchanged GET parameters. If you are using filter_input(), you have to hook into pre_get_posts to … Read more

Add (grand)child pages automatically to nav menu

It’s wise to avoid nav menus in cases like this where things may change frequently. Instead, you could look into using wp_list_pages() – with a custom walker if you need one to format it visually. Try wp_list_pages() right out of the box first and see whether you can just use CSS to style the list … Read more

How to create custom search page

you dont need extra queries, all you would need is to sort the search results by post type. you can find a way to do so here. and then, inside your search.php template, you would need to check for the post-types and act accodringly.. while (have_posts()) : the_post(); $post_type = get_post_field( ‘post_type’, get_the_ID() ); if … Read more