-
AuthorPosts
-
October 13, 2016 at 4:39 am #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
October 14, 2016 at 5:12 pm #699225Hey 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,
YigitOctober 17, 2016 at 3:55 am #699747Brilliant – 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 8 years, 2 months ago by Jason.
October 17, 2016 at 1:45 pm #699979Hi,
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,
YigitJanuary 3, 2017 at 12:22 am #728796I 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;
}January 3, 2017 at 5:36 am #728837Hi,
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,
RikardNovember 12, 2019 at 12:56 am #1155781hi 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,
JasonNovember 12, 2019 at 3:51 pm #1156033Hi,
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,
YigitNovember 13, 2019 at 4:41 am #1156263thanks Yigit – perfect
November 13, 2019 at 9:27 am #1156321Hi 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,
RikardNovember 13, 2019 at 9:30 am #1156324All good to close this one Rikard, thank you
-
AuthorPosts
- The topic ‘Move H1 entry title’ is closed to new replies.