Custom 404 Wordpress with custom fields - wordpress

I'm running into the following problem. I have a 404.php but I need to use some custom fields on that page. So I preferably need to make a page and use that. But I can't seem to override the default behaviour.
Is there any way to fix this?

Try this one:
Remove all the code from the 404.php
put a single line code of your custom template:
<?php get_template_part( 'new-template-name' ); //don't put extension(.php) ?>
Here you have to create a new template with the same above mention name
Thanks.

Here is how I managed to accomplish it:
Create an empty page template in theme directory named 404-content.php with the following lines of code:
<?php
/* Template Name: 404 Content */
Create ACF field group with the desired custom fields for the 404 page (ex. title & contents). The group's post template should be set to "404 Content".
Create a 404 page in WP admin. Select the 404 Content as its template, and fill the custom fields with the desired content. Note the post-id of the page created.
Update 404.php in your theme directory to display your custom fields. For example (replace xxxx with the post-id of your 404 page):
echo get_field('404-page-title', xxxx);
...
echo get_field('404-page-content', xxxx...)
Hope that helps someone :)

Related

Wordpress Custom Template page not displaying

Unable to get my custom created page in page attributes Templates, rest all the pages are still shown in the dropdown but new created page is not listed. I have created a custom page in PHP and uploaded it in wp-content->themes->my-theme in the root directory.
Kindly assist, Thanks
Add at the beginning of your custom page:
<?php
/*
Template Name: Template name
*/
?>
The second template name will the name of your template
Make sure that your template file name is like page_{template-name} and not page-{template-name}.
Also add this at the beginning of the template.
<?php /* Template Name: Example Template */ ?>
Check this out for more details https://developer.wordpress.org/themes/template-files-section/page-template-files/

WordPress, how to use dynamic urls for the same page?

I don't know if it's possible, but I want to configure a WordPress site to render the same page for all URLs that match the format https://example.com/things/<any_word>, the URL must keep its value.
For example,
The following URLs must show the same content:
https://example.com/things/pencil
https://example.com/things/book
https://example.com/things/tv
Your help would be greatly appreciated
There are several options:
1) Register your custom post type and create defalut template (the best option)
2) Add some custom code to page template (single.php or page.php ...) where your call a specific template for a specific category:
<?php
if (get_the_category(get_the_id())=='your-category')
{
get_template_part( 'TEMPLATE_FOLDER/content', 'something' ); // "content-something.php"
} ?>
3) Create a template and choose it for needed pages
https://developer.wordpress.org/themes/template-files-section/page-template-files/
https://developer.wordpress.org/reference/functions/register_post_type/

how to move the physical location of the permalink header in wordpress?

Does anyone know how to move the physical location of a permalink header in wordpress? I dont want it to be the first thing that is seen but rather I want a shortcode item there.
In your page.php you can delete the php function for calling the header ( the_header() ) and put the function to call the shortcode ( do_shortcode() ).
This way the page is not embeding the header.php but get the code of your shortcode at this place of your markup.
Page Template:
You can create a page template in your theme-folder. For this, you can simple duplicate the page.php and call it page-yourname.php. At the top of your page you add the name of the page template:
<?php /* Template Name: Example Template */ ?>
In that file you do the adjustments that you like to do with the shortcode.
https://developer.wordpress.org/themes/template-files-section/page-template-files/
With the template structure of wordpress, the template will automatically be found at the edit screen of your pages. It will be found on the right side under "page attributes".
You can set the template for your individual pages. So your adjustments to the template will only affect your pages, where you selected the template in the page attributes.

Iclude php file in wordpress post

How do I include a php page in a wordpress post?
I know how to include in pages, using /* Template Name: templatename */ and select a value from dropdown attributes. I don't know how to achieve this in a post, can you help?
i have file ex.php and i want to display the contents of the file in post article.
The template file for single posts is single.php
Depending on your theme you might have to create it
(for example copy index.php and name it accordingly)
see http://codex.wordpress.org/Theme_Development#Single_Post_.28single.php.29

How do I create a custom WordPress page?

I want my WordPress blog to have a page called music. On that page I will query the DB for posts with the category music and then change around the look and feel of the posts. So I can't just put a link to /categories/music/ because I want to do custom work on the posts.
Should I put this code in a separate php file and link to it? I think I may lose access to all the nice WordPress API calls if I do that.
I was thinking about using a filter, but I am not sure which one to use. I was thinking something like the following except the_title has not been grabbed yet so I cannot check the title.
function show_music(){
if( is_page() && the_title('','',false) == 'music' ){
echo "got here";
}
}
add_filter('pre_get_posts', 'show_portfolio');
How would you go about this?
You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:
/*
Template Name: Something Goes Here
*/
You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

Resources