Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #698572

    Hi there,
    I’ve like to move the page’s main title to a move traditional location.
    Any chance I can do that?
    I’m using a child theme.
    Thanks,
    Jason
    Image

    #699225

    Hey Jason,

    Please add following code to Functions.php file in Appearance > Editor

    function avia_title_sc( ){
       return get_the_title();
    }
    add_shortcode( 'avia_page_title', 'avia_title_sc' );

    Then add following shortcode to wherever you would like to display the title

    [avia_page_title]

    Best regards,
    Yigit

    #699747

    Brilliant – thank you Yigit.
    The only thing is, it doesn’t pull through the fact it’s an H1, it wraps it in a <p> tag.
    Also, doing it this way means I’d have to manually edit each page – is there a way to add this to – or change the <h1> position in a template?
    Actually, I see I can wrap the shortcode in <h1 class=”main-title entry-title”></h1> so I may be able to run with this.
    Be handy to know if it’s easy enough to change where the page title appears (in a template file).

    • This reply was modified 7 years, 5 months ago by Jason.
    #699979

    Hi,

    Can you please post the link to your example page so we can provide you an accurate solution?

    If you would like to wrap the title in H1 tag, please change the code to following one

    function avia_title_sc( ){
               $output = "
    <h1 class='page-title'>".get_the_title()."</h1>
    ";
               return $output; 
    }
    add_shortcode( 'avia_page_title', 'avia_title_sc' );

    Best regards,
    Yigit

    #728796

    I solved this in a different way that doesn’t require you to then go and edit every page to insert the shortcode, as suggested above. To add the page title as an <h1> tag above the body copy, I added this to functions.php of the Enfold child theme:

    function my_the_content_filter($content) {
    if (is_page() && !is_front_page())
    {
    $content = ‘<h1>’.get_the_title().'</h1>’.$content;
    }
    return $content;
    }
    add_filter( ‘the_content’, ‘my_the_content_filter’ );

    This intercepts all attempts at producing the page content, for all pages other than the home page, and inserts the page title before the content.

    Then to hide the page title from the page banner area, I added this CSS snippet on the Enfold Child / General Styling tab:

    /* Hide page title in banner area. */
    h1.main-title {
    display: none;
    }

    #728837

    Hi,

    Great, glad you found a solution and thanks for sharing! Let us know if you should need any further help on the topic.

    Best regards,
    Rikard

    #1155781

    hi there,
    bnewburger’s solution would do the trick, but his code throws me an error.
    can someone please check it (i’m not a programmer) or, if there is a better solution out there now, can someone please let me know?
    many thanks,
    Jason

    #1156033

    Hi,

    Please try copying the code from below

    function my_the_content_filter($content) {
    if (is_page() && !is_front_page())
    {
    $content = '<h1>'.get_the_title().'</h1>'.$content;
    }
    return $content;
    }
    add_filter( 'the_content', 'my_the_content_filter' );

    Best regards,
    Yigit

    #1156263

    thanks Yigit – perfect

    #1156321

    Hi Jason,

    Great, I’m glad that Yigit could help you out. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #1156324

    All good to close this one Rikard, thank you

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Move H1 entry title’ is closed to new replies.