[Resolved] Add a page with php

Home Forums Support [Resolved] Add a page with php

Home Forums Support Add a page with php

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #482352
    Thomas

    Is there a way to add a page containing php?
    I want to add a contact page with email form.
    I tried uploading the page (contact.php) to the theme folder, and the child-theme folder. However when I enter the url, it gives a 404 error.

    I could make a shortcode, but it will make my functions.php significantly larger and I hope to prevent that.

    And what part of page.php should I edit?
    Everything between do_action( 'generate_before_main_content' ); and do_action( 'generate_after_main_content' );?
    (Ofcourse I won’t actually edit page.php, but copy it, in order to use the same template).

    #482684
    Leo
    Staff
    Customer Support

    Hi there,

    What are you trying to achieve?

    You might be able to add PHP using GP hooks and just target to specific page:
    https://docs.generatepress.com/article/hooks-overview/
    https://docs.generatepress.com/article/using-hooks-conditional-tags/

    Let me know if this helps.

    #482719
    Thomas

    Using hooks with conditional tags probably will do the trick, but I’m not really enthusiastic about this solution. It would mean I have to write the entire code for this page in GP hooks;

    I want to display an email form on a contact-page, this code already takes up around 120 lines and there is more to be added. Therefor I would prefer a solution where I can upload a page to wp-content or my child-theme and visit it via url/url/contact.php.
    However, when I try this, I’m being referred to the 404 page.

    #483082
    Tom
    Lead Developer
    Lead Developer

    You could create a custom page template: https://developer.wordpress.org/themes/template-files-section/page-template-files/

    That’s probably the best method ๐Ÿ™‚

    #483391
    Thomas

    A custom page template seems to be the way to go, thanks for pointing me in the right direction.

    One more question. How can I remove the featured image / background color on this page?
    This is the best result I had:
    null

    As you can see the background color still exists, and I’d like to remove it.

    #483720
    Tom
    Lead Developer
    Lead Developer

    The white background color behind the “Contact” title?

    #490262
    Thomas

    Sorry for the late reply. We made our website available for the public and were very busy with that.

    The white background is what’s supose to be there. Maybe the picture isn’t all that clear because I’m not using a featured image and in this case you only see the back-ground color/color-overlay of the featured image.

    What I want is to remove the featured image, just like the 404/forums/member-pages have no featured image.

    #490697
    Tom
    Lead Developer
    Lead Developer

    Is there any way you can link me to that page so I can take a closer look?

    #493438
    Thomas

    Yes, I made an example for you.
    I actually added a message to the page for you Tom.
    Trying to explain what I want and what I’ve done so far.

    https://vespa-ciao.nl/beta/test/

    Thanks for looking into this.
    Best regards.

    #494011
    Tom
    Lead Developer
    Lead Developer

    So this is due to the page header being set globally to all pages.

    We can likely use a filter to disable it when on these specific custom post types – would that work for you?

    #495320
    Thomas

    Certainly, that would work for me, can you tell me how I set this filter?

    #495457
    Tom
    Lead Developer
    Lead Developer

    I just went to write the function, but we need a conditional so we only disable it on specific pages. I thought the page was a custom page template, but it doesn’t look like it.

    Are you going to be disabling the page header on a lot of pages, or only a few?

    #495479
    Thomas

    Hmm, strange? I did exactly as described in your link for making page templates.
    The test-page I made for you is in my child theme directory and is called page-test.php

    Edit:
    Ok I find out why, my bad.
    I forgot the template name: ... part on top of the page, my bad.
    Now it is a template as supposed to.

    #500892
    Thomas

    Hi there,

    Is it possible this topic lost your attention?
    Still looking for a way to remove the featured image ๐Ÿ™‚

    I took another look at it and the page is now a template as supposed to.
    So your initial idea to write the function for specific custom template pages should work.

    #501611
    Tom
    Lead Developer
    Lead Developer

    Sorry about that! Not sure how I missed your last reply.

    Let’s try this:

    add_filter( 'generate_page_header_options', 'tu_remove_page_header_template' );
    function tu_remove_page_header_template( $options ) {
        if ( is_page_template( 'page-test.php' ) ) {
            $options['content'] = '';
        }
    
        return $options;
    }

    This assumes your custom page template is named: page-test.php

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.