- This topic has 7 replies, 2 voices, and was last updated 4 years, 5 months ago by David.
-
AuthorPosts
-
November 7, 2019 at 3:25 am #1055684Joe
Hi there,
I’m struggling 🙂
I’m trying to add a social icon to the mobile menu.
Having looked at many previous posts I’ve had a few attempts. This is the latest I dropped into a hook element – but it blanks my site (using Hook: inside_mobile_menu_bar):
<?php
add_action( ‘generate_inside_mobile_header’,’nb_mobile_menu_html’ );
function nb_mobile_menu_html() { ?><?php }
I’ve tried adding <script></script> tags too. But still it doesn’t execute properly (blank page, and yes the execute PHP is checked.
Yet, if I strip out all the PHP and just use the HTML it works fine.
Q1 – Can I just simply use the HTML in the hook or is using PHP better practice?
Q2 – What PHP do I paste into the element box – exactly? Do I include script tags, if so where?
Q3 – Or do I need to use in combination with code snippets? I’ve created a snippet, but I’m not sure how to call the snippet from the hook, if that’s what I need to do.Some exact code to cut and paste would be wonderful.
Thanks!
November 7, 2019 at 5:01 am #1055784DavidStaffCustomer SupportHi there,
that code is a PHP snippet and would need to go in the Code Snippet plugin.
Thats all you need to do.November 7, 2019 at 9:48 am #1056185JoeHey David,
It’s not working for me.
I put this code into the Code Snippet program and the RSS icon doesn’t display on mobile (as I said it does if I just use the html).
add_action( ‘generate_inside_mobile_menu_bar’,’nb_mobile_menu_html’ );
function nb_mobile_menu_html() { ?><?php }
The documentation is unclear to me with regard to how I do this. Are Code Snippet and Element Hooks alternatives to accomplish the same thing, or do I need to call the Code Snippet from inside the element hook?
Also, am I using the correct hook for putting this next to the search icon?
November 7, 2019 at 11:13 am #1056256DavidStaffCustomer SupportCode Snippets can be used for any type of php function – which would alternatively be added to a Child Themes function.php file.
The function you’re using ie. add_action attaches your function ( nb_mobile_menu_html ) to theinside_mobile_menu_bar
hook. That is all that is required.In the Hook Element it’s doing the same thing without the need for the add_action or function. So in Elements you would just add the HTML you want to output.
That hook is correct but only exists if it has been enabled, eg. Navigation search is enabled.
I would use the hook element method. If you’re not seeing anything output then try hooking in just some plain text to see whether it is your HTML that is not working.
November 7, 2019 at 9:33 pm #1056547JoeThanks David.
So to confirm… in Hook Elements I can just used the HTML (which works), and there is no need for the PHP?
It’s just that all the forum advise says to use PHP to inject the HTML – so which way is better practice?
November 8, 2019 at 1:58 am #1056637DavidStaffCustomer SupportThats correct for what you require only the HTML is needed.
The Hook Element is using PHP – its performing theadd_action('the_hook','the_function');
November 8, 2019 at 2:31 am #1056667JoeThanks for the clarity.
November 8, 2019 at 2:34 am #1056670DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.