• Hi,
    I want to add this code to end of all posts:

    <iframe src="http://test.com/query.php?&q={QUERY}"
                        width="100%" frameborder="0"></iframe>

    And replace “QUERY” and “query” with the post title.
    I tried to add a short code to get the page title and then edited the code like this, but did not work:

    <iframe src="http://test.com/[page_title].php?&q={[page_title]}"
                        width="100%" frameborder="0"></iframe>

    Also tried this, but no success:

    <iframe src="http://test.com/<?php Echo get_the_title();?>.php?&q={<?php Echo get_the_title();?>}"
                        width="100%" frameborder="0"></iframe>
Viewing 15 replies - 1 through 15 (of 21 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You can do this with jQuery, just make sure that the page title and post title are in the DOM:

    jQuery(document).ready(function($) {
        var target = $('.post'),
            iframe = $('<iframe>'),
            pageTitle = $('.page-title'),
            postTitle = target.find('.post-title');
    
        iframe.attr('src', 'http://example.com' + pageTitle + '.php&q=' + postTitle ';
    
        target.append(iframe);
    });

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oh right you just can’t get the page title? What do you mean by page title?

    Thread Starter m107

    (@m107)

    @andrew, I assumed the page title should be the same as post title, that’s why i mentioned it.
    What did you mean from “DOM”?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The page title is the same as the post title, I thought. Does it not return the same thing?

    Thread Starter m107

    (@m107)

    In my case, it does not return anything. Actually I want the post title to be replaced with that “query” string.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    In which file are you writing this code?

    Thread Starter m107

    (@m107)

    single post file for my theme.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Are you okay to test some code and break your website momentarily?

    Thread Starter m107

    (@m107)

    Sure, please 🙂

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’m hoping that this will result in a blank white screen with some plain text…

    Can you add this to your code:

    var_dump(get_the_title()); exit;

    Thread Starter m107

    (@m107)

    I used it before: Echo get_the_title() and it worked.

    Andrew, getting the page title is not the problem, replacing it with the string in my code is my problem.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    So when you view your page’s source code, in the browser, does it appear like this:

    <iframe src="http://test.com/.php?&q={}"
                        width="100%" frameborder="0"></iframe>

    ?

    Thread Starter m107

    (@m107)

    no, I see the nginx error, so the code is wrong.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Could you paste here the code you’re currently using for the iFrame that causes the error?

    Thread Starter m107

    (@m107)

    <iframe src=”http://test.com/&lt;?php Echo get_the_title();?>.php?&q={<?php Echo get_the_title();?>}”
    width=”100%” frameborder=”0″></iframe>

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘A code to get the page title’ is closed to new replies.