1

If I have a plugin that prints (simply) "Hello World", and I want it be outside of the main container, so, like this:

<h1>Hello world!</h1>
<div id="content">
    .
    .
    .
</div>

Instead of:

<div id="content">
    <h1>Hello world!</h1>
    .
    .
    .
</div>

How can I make that work?

I created a child-theme and I don't want to edit the parent theme files (if even needed).

I saw a solution that you can do something like this:

add_action('__before_main_container', 'my_func', 0);

(In the functions.php file) and my_func would print some html, but that is not working for some reason (it doesn't display anything in the page).

Another thing with this, the plugin I use needs to be added like so:

[plugin id="1"]

to the page I want it be on. The problem with this is I cant just do:

echo '[plugin id="1"]';

because that would not trigger the plugin!

So, what can I do to make that work?

(I want to do this because I want something specific full-width but not the container itself)

EDIT: Ok I saw that I can override header.php, that's great, but how can I insert the plugin there only for specific pages? or pages that include:

[plugin id="1"]

for example?

3

it looks like you're using shortcode to execute your plugin. so instead of just

echo '[plugin id="1"]';

use this:

echo do_shortcode('[plugin id="1"]');

put this in the php file where you want it to load. For example, right above the

<div id="content">

this can be in whatever file you wish to execute the shortcode

  • How can I do this only for pages that include that [plugin id="1"]? – Naor Hadar Nov 22 '16 at 20:05
  • holw are you determining which pages will have that plugin loading? pages, posts, homepage, blogpage, cpts etc? – rudtek Nov 22 '16 at 20:10
  • I wanted to determine that by the page content (like regular plugins do) but I eventually did it just with the is_front_page() function. If you have any other idea please let me know :) – Naor Hadar Nov 22 '16 at 20:15
  • 1
    no, if you only want it on the front page that is the best way. Plugins do it like that too. The is_front_page would just be in their code. We're pulling it a bit later but the result is the same. – rudtek Nov 22 '16 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.