Show widget outside sidebar - WORDPRESS - css

I'm using a theme total made by me. I need to show Sidebar Login plugin's widget in header.
I tried this in header.php:
<div class="login"><?php the_widget('sidebar-login');?></div>
Page load without error and I have a space occupied by that div, but there is nothing inside. Maybe it is because I insert no $instance and no $args after $widget, but I don't know what they are.Maybe i need specific code for the plugin i linked.Thank you in advance.

Ciao Michele,
are you trying to use Sidebar Login plugin from Mike Jolley?
According to the codex, the_widget method wants the plugin Class Name, not the namespace, your code should work if you use something like this:
<?php the_widget('Sidebar_Login_Widget');?>
If you are using a different plugin you have to check the correct class name in php code.

Related

Elementor - adding custom code right after the <head> tag

Not sure if this is only problem for Elementor full width template, but it seems to override theme header.php. I tried achieving my goal by using elementor custom code feature, but it adds my code somewhere in middle of the tag.
What is the propper way of adding my own custom code as the first thing that is after the element?
You are right Elementor overrides the theme's header.php file so importing your code to this file is not effective. You need to add custom function to earn your goal. With the wp-head action you could add the code right into your header and Elementor will not override it.
Add this code to the functions.php file od your active theme.
add_action('wp_head', 'custom_head_function');
function custom_head_function(){
?>
YOUR HEADER CODE HERE
<?php
};
UPDATE - If you want to set your code at the top
As sephsekla mentioned in comment, there is a way to set the priority into your action to get it to the top. Try to set value to -999. So, choose a very low number and if there is no other lower number in your plugin or theme you will go straight to the top.
add_action('wp_head', 'custom_head_function', -999);
function custom_head_function(){
?>
YOUR HEADER CODE HERE
<?php
};
Elementor now supports custom code (javascript, html, etc) and supports the specific use of elements in the head of the page.
What you are looking for you can find at the Wordpress Dashboard> Elementor > Custom Code . Then you will be able to add a custom code to the head: https://elementor.com/help/custom-code-pro/

Wordpress static Form on any page - Plugin, Widget or Shortcode?

I am frankly new to wordpress but programm in PHP.
Task:
I have a form (don't wanna use a form plugin) and want to include this form on either 1. Sidebar or 2. within content of any Page except one (Contact-page).
I want to programm the Widget, Shortcode or Plugin bymyself. I don't need a tutorial how to programm this.
Question:
What do you advise me to use: a shortcode, plugin, widget or a "hack" in the template (f.e. if ($page!=="contact"){...}
The answer should consider
Ease and flexibility of use
Short time to develop
Speed of Rendering
Thanks for advise of experienced Wordpress Users/Developpers.
PS: the form is very simple maybe there is even another fast way you know how to do this.
Try This
1)first to fall you make a page templates of contact page.(make copy of page.php than only change the name of templates)
2)than that template in you make your custom form.
3)that page template you apply in your contact page.
Make a template-myForm.php file, and populate it with following:
<?php
/**
* Template for displaying search forms for My Web Site
*
*/
?>
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<!-- your form content-->
</form>
Add to site <?php get_template_part( 'template', 'myForm' ); ?> where you want a custom search form. I used it for search form, so it was easy to make it into widget also. I used separate template file for site search, and searcform.php for search widget. If you are aiming at different kind of form tag, you have to create that a Widget.
It is a class Your_Widget extends WP_Widget, which for you can find tutorials on your own, or just check out PHP code file: wp-includes/class-wp-widget.php in your Wordpress copy and extend it. Me personally use tutorials. I find it more simple.
So, to summ up, you would have two copies of your form - one to show as a template part, and an another one for sidebar or other registered widget area. If it is identicall in both versions, using this solution you would have to remember to keep changing it in two places (which is again simpler than hard-coding).
For me beeing not a native English speaker and just a part time Wordpress coder, this is what I offer. More integrated and PHP-programming-friendly solution, find in Wordpress forums, here on stackoverflow and Wordpress.org site.
I also am aware this is not exactly what you are looking for - not using shortcode. I hope this will kick you off into Wordpress world, and you will find how to offer a custom form to your users!
Good luck!

Adding A Button Between post-content and Related Posts Thumbnail Plugin on WordPress

I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the pluginĀ“s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.

why is the <?php wp_head ?> tag creating a top margin at the top of my theme header

Hey people, I've been coming here for a while but just decided to join.
I'm new to php and I'm trying to make a website with WordPress as the CMS.
Anyway, I'm basically making my own theme because I don't want my website to look like a blog, and it's going pretty smoothly so far but theres this huge top margin gap in the browser even when I set margins to 0px.
I tried trial and error and found out that it's being caused by: <?php wp_head(); ?>
It's two different things.
1. wp_head() function
wp_head() is a template tag to print whatever plugin / theme specific function used by wordpress action. Read codex for more detail about it.
2. The admin bar
The top margin, is generated by wordpress's admin bar.
To fix this for logged in users you can do a couple of things:
Disable admin bar from the admin:
Go to admin panel
Users >> User Profile
Uncheck 'when viewing
site' on 'Show Admin Bar'
Remove the admin bar from your theme entirely:
Open your functions.php
Add this to it:
function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Remove only the code which creates the css:
Open your functions.php
Add this to it:
function my_filter_head() { remove_action('wp_head', '_admin_bar_bump_cb'); }
add_action('get_header', 'my_filter_head');
Note: Extensive updates are from #hitautodestruct
you neeed to call wp_footer() in your footer
just insert this line <?php wp_footer();?> into your footer.php file
If you have updated your wordpress install to the latest version.. there seems to be some bug with the admin bar...
were it would produce an inline stylesheet appended to the top of your pages.. causing the margin-top:28px
see here
1 recomendation is to put a new function into your functions.php file located in your theme folder.. this will completly remove the bar, so no users of your theme will have any of the same issues!
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Not sure if this will help.. but worth a shot.. also turning off the admin bar while viewing the front end of the site under your profile page..

widgets_on_pages not working

Hello i'm using widgets_on_pages to place widgets on pages, i installed it and added a widget to the panel in my admin section, then i added [widgets_on_pages id=2] ("its the 2nd sidebar and it said i should add this") into my html on the place where the widget should appear but it only shows the code i added in pure text, nothing else happens, anyone know what i'm doing wrong?
If I understand correctly then the following applies... if not, apologies.
You should not need to do it this way. It seems that Vincent, you are trying to add the shortcode into a theme php file... this is incorrect and the shortcode is for adding into the page/post content by the post/page editor.
To add a Widgets on Pages sidebar to a template then v 0.0.7 (I believe) has built in template tags (see link text). This should allow you to add the following I think
<?php widgets_on_template("2"); ?>
Try this
<?php echo do_shortcode('[widgets_on_pages id=2]'] ?>

Resources