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

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/

Related

Add comments to wordpress inspect element page

As the title says, I want to add some sort of signature with comments on my wordpress index file, thing is - there are 30 different index files and none of them seems to work
If I understand correctly, it'll just be a case of adding some HTML comments (not PHP comments as they won't show in the source code) in your theme files. Bear in mind that editing a theme won't work if someone else made it and releases updates to it as it'll overwrite your changes if you update it.
The best place to add in the comments is to either open the header.php file and place your HTML comments after the opening <body> tag. If your theme doesn't include a header file, you could always add your comments to the top of your themes index.php file instead.
Your theme should be located within /wp-content/themes/YOUR-THEME/.
Alternatively, you could also place HTML comments between the <head> tags of your theme so they show up a bit higher in the source code. To do this, it's probably best to use an action hook instead. Place this in your themes functions.php file:
add_action( 'wp_head', 'add_signature_to_theme', 1, 0 );
function add_signature_to_theme() {
?><!-- Welcome to my website. --><?php
}
The wp_head action hook documentation is useful to have as reference as well if you'd like a bit more information on what it is and what it does.

Show widget outside sidebar - WORDPRESS

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.

Where can WordPress (self-installed) shortcodes be rendered?

I've looked around for this but can't seem to find a definite answer. I want to know where WordPress shortcodes are supported within the (self-hosted) platform - meaning where can I safely place shortcode content and expect it to be rendered? I know I can use them in post and page content, and some widgets that output something. But can I use them in other plugins (that also output something), and which widgets are supported? Do custom plugins need to have something enabled that allows them to render shortcode content?
This page says:
By default, WordPress does not support shortcodes within Sidebar Widgets. It only expands the shortcodes within the content of a Post, Page, or custom post type.
... although I've gotten shortcodes to work in the arbitrary text widget, so that information doesn't seem accurate. It also suggests I install this plugin that hasn't been updated in years.
Is there any clarification somewhere on this that I've missed?
You can use:
<?php do_shortcode('name_of_shortcode'); ?>
e.g echo do_shortcode('[gallery autoplay=no]');
and it will render this shortcode. You can place it in functions.php, header.php, footer.php.
EDIT:
If you want it to work in Text Widget, all you need is to add this line of code in functions.php file:
add_filter('widget_text', 'do_shortcode');

How to add my own created drop down menu to theme?

I have created my own drop down menu in html&css. So,anyone can guide me how, i can add my self made dropdown menu to my own custom WordPress theme ?
I don't want to use any Plugin because it would not give me same look as my own drop down menu.
Thanks In advance.
Its not clear if you already have any register_nav_menus. If you have any registered menu, you need to call it through wp_nav_menu and use you own css in style.css of your theme. After adding your css in style.css, you need to check this css hierarchy of Unordered List generated by wp_nav_menu.
You can also check Menu_Item_CSS_Classes section in wp_nav_menu documentation.
If your theme don't have any register_nav_menus, add this in your functions.php file to make it more managale in future.
Pretty straightforward. Somewhere in your theme you should see a function called wp_nav_menu:
<?php wp_nav_menu(); ?>
This is the default navigation. Replace it with your own HTML, and add the CSS to the style.css file. If there's any JavaScript, you'll obviously need to include that on the site, too.

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