Placing content before post title, right below top menu

Hi, I want to add custom code in the space between the top menu bar and the title of the post. I have tried the following code in my child theme:

add_filter (‘the_title’, ‘add_AdToTitle’, 11 );
function add_AdToTitle ( $title ) {
$Ad = do_shortcode(‘MY CODE’);
return is_singular(‘post’) ? $Ad.$title : $title;
}

But that puts the added content inside the H1 tag. Not good. I also tried to change “the_title” to “the_content” but that puts my code below the featured image of the post and above the content. Not what i want.

Any ideas?

Hi @smaspararguiden,
Thanks for reaching out.

You can try by using the X and Pro Specific Actions and Filters hooks to call your function instead of using the the_title hook.

add_action( 'x_after_masthead_end', 'add_global_header' );
function add_global_header() 
{
    echo do_shortcode('Your Code');
}

To know more on our theme hooks, please go through this article: https://theme.co/docs/actions-filters-and-hooks#x-and-pro-specific-actions-and-filters

Remember that the suggestion in the above-mentioned thread will work if copied as it is and doesn’t conflict with any existing code.
Please note that the code provided serves only as a guide to help you get started custom coding on your own if there’s no option offered in our theme or the products we bundle.
We do not provide support for custom codes and the modified child theme, that means we can’t fix it in case it conflicts with something in your site nor will we enhance it.

Thanks

Thanks, that was good stuff.

However, when I try that snippet the custom code appears AFTER the post featured image. I want it BEFORE the post title.

Hi @smaspararguiden,

You can test your code with our given hooks documentation as @tristup. You can use hooks that are required for your projects.

Please note that we do not provide support for custom development even if you use our theme’s hooks because we’d be working on your customizations if we do that and we only offer that service for our Elite customers. If you want us to customize your site, you might want to subscribe to our Elite service here https://theme.co/elite.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.