Support » Developing with WordPress » Use content from one page on another one

  • Hello,
    It might be a silly question, but cannot find the answer anywhere.
    I need to get the featured image from “about us” page and use it on “home page”. I am using this code:

    <?php
    if ( has_post_thumbnail() ) {
        $post_thumbnail_id = get_post_thumbnail_id();
        $image_url = wp_get_attachment_image_src( $post_thumbnail_id, 'full' )[0];
    }
    <section style="background-image:url('<?php echo $image_url; ?>');">
    ?>

    to display image as background, but need to load exactly the same img on another page.
    And can I also do the same with the_content(); and the_title();?

Viewing 3 replies - 1 through 3 (of 3 total)
  • First thing you need to do is install and activate the Insert Pages plugin. Upon activation simply go to Posts » Add New to see it in action. If you use visual editor, then you will notice a new button labeled ‘Insert Page’ in the menu

    • This reply was modified 10 months, 3 weeks ago by surveypacific.
    Thread Starter ragariusz

    (@ragariusz)

    Hi,
    Thank you, that’s a nice plugin, but i think it’s not going to help me. I’m not using visual editor, what I’m trying to do is ‘connecting’ the static website I made in html/css with wordpress. Insert Pages plugin does not let me put this thumbnail anywhere else than in current page content field. The solution I found is using Advanced Custom Fields – although it does not let me use “featured image” (or I just don’t know how), I can just save image in the custom field and use the same one on another page.

    Moderator bcworkz

    (@bcworkz)

    get_post_thumbnail_id() will accept an ID or WP_Post object argument for a different page. Without the argument it gets the current page’s featured image ID. Unless you have a front page specific template, you also need if ( is_home()) logic to only get another page’s featured image ID when true, otherwise pass nothing or null to get the default.
    https://developer.wordpress.org/reference/functions/get_post_thumbnail_id/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use content from one page on another one’ is closed to new replies.