Add html code at the bottom of one page

Dear Support,

Im trying to add an html code to the bottom of only one blog post page

I already have an additional “author” box that goes at the bottom of all my blog posts (added via functions.php), but now I want to add an html code to the bottom of only this blog post and I need it to come under the author box.

Here’s my html code:

<div class=”fb-comments” data-href=”smokingcessationformula.com” data-numposts=”8″></div>

Please let me know how to do so.

Thanks in advance.

Howdy, @nourmoubayed!

To have content only show up using a hook on a specific post, you would need to use a condition to check that you’re on that post before outputting your content. The first thing you’ll need to do is get the ID of your post, which happens to be 30023 in this case. You can find this either in the WordPress admin for the post, or by inspecting the frontend of your site using the developer tools of your browser and looking for the dynamic class on the <body> that references the page/post ID. Once you have this ID, you can then do something like the following in the functions.php file of your child theme:

function my_custom_content() {
  if ( get_the_ID() == 30023 ) {
    echo 'My custom content.';
  }
}

add_action( 'x_before_the_content_end', 'my_custom_content' );

Here we’re hooking our custom output into the x_before_the_content_end action using our function, and inside that function using get_the_ID() to check if ID of the current page/post matches the page we’re looking to target. If it does, we can then output our custom content.

You can utilize this in conjunction with whatever custom code you’re already using to output your author shortcode and make adjustments as necessary.

Cheers!

1 Like

Worked Great ! Thanks for the help

You’re welcome.

1 Like

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