how to move the physical location of the permalink header in wordpress? - 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.

Related

Wordpress: How can I create a page template out of an existing page?

I need to apply the same content on over 4000 Wordpress pages. Now to make it as easy as possible. I create a single page and designed it with the content. So what I want to do now is create a template out of this page. Is there any possibility to export the page as php code to put it in the theme as a template?
(It hast to be the exact content as the template file)
I am also open-minded for other Ideas to solve this problem. Thanks a lot!
Yes, you can create a template and apply your template to your pages.
With the content that you wish to apply to your pages, create a .php file. At the top of this.php (called say page-mycontent.php) file add this header:
<?php
/* Template Name: My Template */
?>
Now the template will appear in the admin panel for Page - Edit on the right hand side.
Code Changes in header.php and page.php
Your changes are in both the header and the loop. So I suggest creating two templates, one for the header and one for the body.
In your header.php, if you name your header code as header-myheader.php then pull your new header template into header.php like so:
<?php get_header('myheader'); ?>
And similarly add your body code (called mytemplate.php say) into page.php like so:
<?php get_template_part('mytemplate'); ?>

Content written in the Page edit box not showing in the published page in Wordpress

I am not sure what I am missing. Please guide me and I apologize if my knowledge is too less.
I have a home template file i.e. template-home.php which actually contains nothing for now and is only containing the following lines ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
get_footer();
?>
I have created a page from wp admin and given the page title "Home" then I selected template "Homepage" for this page I have created from wp admin. Hence I have set the static front page to display "Home". Its perfectly showing the Home page as front page. But when I am giving any content in the edit box of the page "Home" from wp-admin and updating, those contents are not displaying in frontend. But if I put any content in the "Homepage" template , only then its getting displayed. I am giving an example what I tried below-
When I am giving the following in the page edit box then nothing is displayed in real.
[rev_slider_vc alias="homebanner" title="Home Slideshow"]
For your information the above is shortcode of revolution slider which is working perfectly , if I use it in any post. So the shortcode has no error for sure. Another thing whatever I write in the content box is actually not getting displayed in real.
Now the slider code, if I am putting directly into the Home template i.e. template-home.php then slider is getting displayed. The code is as follows ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
// Revolution Slider
putRevSlider('homebanner', 'homepage');
get_footer();
?>
Though my purpose is getting served well by putting code into the template file directly. But I want that the content I put in the edit box of the page from wp admin can get displayed in real. So what I need to do for that ?
Read https://codex.wordpress.org/The_Loop and https://developer.wordpress.org/reference/functions/the_content/
You need a loop and you need the_content to grab the content from the text editor.
A very basic example:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
the_content();
//
} // end while
} // end if
?>
Work with that first with some plain text to test the loop.
Then add your shortcode for the slider [rev_slider_vc alias="homebanner" title="Home Slideshow"] in the text editor. And, look at the docs for the slider on how to place the function putRevSlider('homebanner', 'homepage'); directly in the page template file, if you want to do that rather than using the shortcode in the editor.
See https://codex.wordpress.org/Theme_Development for how WordPress themes are structured and the types of basic files you need in each theme, i.e. index.php, style.css, etc.

Two pages with same content

How to create two pages with same content?
For example, the first page should be with a header menu and the second page should be without a header menu.
The page of my theme has an options without header
Or I can use two different templates of page, but the content of pages should be the same.
You can read the documentation here.
Create a file, called page-mytemplate.php under your theme directory.
In that file, start with this:
<?php
/*
Template Name: My Custom Page
*/
Create a page, and set the template to My Custom Page.
At here you can do whatever you want.
For the other page, repeat the steps, but just call the other template something different name.
EDIT
When you want to show the same content with different templates, just simple get the content of the page:
$post = get_post($postId);
echo $post->post_title ."<br />";
echo $post->post_content;
You can wrap this with your two template page. See the documentation here

Custom 404 Wordpress with custom fields

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 :)

Make another content list as content file of wordpress

I have page I want to display the page in different style (not as the content.php file ) so now I made copy the content.php file and just modified it. I want to display only for one page and other pages should display like content.php . So how can I change the index page to display the particular as new content-list page. My page name is News and it should be display like content-list.php.
For display indiviual page you have to make a Template for that page and from
Dashboard-->Pages open the page where you want to display that template, on right hand side you have seen TAMPLATE-->DEFAULT TEMPLATE, select template you have created...
Syntax for new template
<?php
/*Template Name:abc
*/
?>
<?php get_header();?>
<!--------------------------------------->
CONTENT FOR PAGE
<!--------------------------------------->
<?php get_Footer();?>
I don't know about which file you're referring to as content.php
I have page i want display the page in different style
So, if you want to display a page with a different style, you should have a look at WordPress Template Hierarchy.
You can create another page template, use custom files like header-{name}.php and footer-{name}.php and use get_header() and get_footer() with the appropriate arguments(the {name} you mentionned to call these files.

Resources