How to display the menu name of a menu in wordpress - wordpress

I have created a menu with the name "alggemeen" and added some items to it.
I have assigned the menu to the theme location Footer menu with the slug 'footer-menu'.
Now I know how to display the content of menu and also the menu_location. But I want to display the name the wordpress admin will provide in backend for the menu, on my website.
I would like to echo the name of the menu that has been allocated to the menu with a theme location of 'Footer Menu(slug = 'footer-menu')'.
So as shown above in the picture Currently alggemeen is the menu assigned to Footer Menu so my front end should echo algemeen.

Try this code :
$menu_location = 'header';
$menu_locations = get_nav_menu_locations();
$menu_object = (isset($menu_locations[$menu_location]) ? wp_get_nav_menu_object($menu_locations[$menu_location]) : null);
$menu_name = (isset($menu_object->name) ? $menu_object->name : '');
echo esc_html($menu_name);

Related

Get URL of image placed in my Footer area in Wordpress as widget

I created widget area (Footer area) for my Wordpress theme where I can add Image widget. The thing is that I would like to get url of image that is into my Footer area as widget. Is there a function for that?
In functions.php I add:
function widgets() {
register_sidebar(
array(
'name' => 'Footer area',
'id'=> 'footer_area1'
)
);
}
In my header.php I add:
<div id="Footer">
<?php
dynamic_sidebar('footer_area1');
?>
</div>
Now, I can add all sorts of widgets (Image, Text, Meta, Menu etc.) into that area. But when I add Image widget that is default widget, I would like to get URL of image/picture that is placed in that area through Image widget. How can I get url?
I hope that clears the question.
This will work for you
<?php dynamic_sidebar( 'footer_area1' ); ?>
As per the documentation https://developer.wordpress.org/reference/functions/dynamic_sidebar/
Edit
If you would like to extend the Image Widget, you can try look at using this https://codex.wordpress.org/Function_Reference/the_widget
But for a much more easier approach, I'd suggest uploading your image to Media Library and then copying the image url from there and pasting it into a custom widget area.
Widget settings are stored in the options table. You can get the content of an option field with get_option(). Replace MY_WIDGET with the actual ID of your widget:
$widget = get_option( 'widget_MY_WIDGET' );
Use print_r to inspect the returned value (false if option does not exist) and get an idea of how to grab the desired value:
print_r( $widget );
EDIT :
To find the widget id :
Open Appearance->Widgets
On top of the screen, find “Screen Options” and open it
Click on “Enable Accessibility Mode”
Find a widget for which you want to know ID and click the “Edit” button
In the address bar, find “editwidget=something” where “something” is the ID you are looking for

Get setting form wordpress customizer and display in a url

How can I create a custom url like this :
www.my-wordpress-blog.com/?layout=fullwidth
www.my-wordpress-blog.com/?layout=grid
www.my-wordpress-blog.com/?layout=list
See Example what excepted as output,
http://themes.themegoods2.com/letsblog/?layout=fullwidth
http://gleedthemes.com/themes/elora/?layout=2
I tried looking on Google, but no "how to" tutorials show up for anything like this.
How create custom URL
Step:1 Login to admin panel and go to "Appreance->Menu"
Step:2 Use the Custom Links panel to add a custom link to your menu, such as a link to an external website.
Step:3 Simply type in the website URL in the URL field and the menu name in the Link Text field.
Step:4 Click the Add to Menu button when done. Use the same steps outlined previously to adjust the order of the menu item and click the Save Menu button at the top or bottom of the screen to save your changes.
Please refer following for more information,
http://www.templatemonster.com/help/wordpress-add-custom-link-menu.html#gref
How To set Layout page
Add page from page menu
Select a Right side Page attribute select a template from there.
publish page and visit a menu from front side.
Final Solution Suggested By [Sociopath]
Path : wp-content/themes/yourtheme/functions.php
add this code at the end of file.
if( ! function_exists( 'themename_demo_set_the_header_layout' ) ){
/**
* Set the demo header layout from child theme.
* #param unknown_type $header
* #return Ambigous <NULL, string>
*/
function themename_demo_set_the_header_layout( $header = 'layout1' ) {
$header = isset( $_GET['header'] ) ? trim( $_GET['header'] ) : null;
// Add more checking conditions here.
return $header;
}
add_filter( 'themename_set_my_header_layout', 'themename_demo_set_the_header_layout', 10, 1 );
}

Top-level menu item to edit a specific page

I'm not sure if this is possible or advisable, but I'd like to have a top-level menu item on the sidebar in the admin dashboard that links to a specific page within wordpress for editing.
Maybe there's a better way of doing this... here's the functionality I'm after:
I have a page called "Upgrade Contents" where my client can edit the contents of their upgrade package sitewide. I'd like them to be able to edit this page directly from the admin dashboard, like a setting page. Problem is, I don't know how to add a link to edit this page to the admin AND I already have everything set up with ACF using this page.
Is adding a link easy to do or should I just scrap it and make a settings page for my theme and add THAT to the admin?
To add a link at the top level of the menu you can add an item to the global $menu array, like this:
function link_to_user_settings() {
global $menu;
$title = 'User Settings';
$url = 'URL_OF_YOUR_PAGE';
$position = 73;
$permission = 'read';
$icon = 'dashicons-admin-links';
$menu[$position] = array( $title, $permission, $url, '', 'menu-top', '', $icon );
}
add_action( 'admin_menu', 'link_to_user_settings' );
Change the variables accordingly to your needs.
The $position var is where you want the link to appear based on the default positions you can find at the add_menu_page() documentation (in my example 73 means after the Users menu item).

open all links on post in new tab , target="_blank"

how can i set all links ( internals , externals , photos ) on all posts (WordPress) in new tab (target="_blank") ?
i don`t want to open menu links and other themes links in new tab ! only links on post.
functions codes or another code
if your theme adds class to body, you should have post class "single-post"
then in JS - add:
$(".single-post a").attr("target","_blank");
if your theme doesn't add class to body, add this:
<body <?php body_class($class); ?>>

WordPress Menu highlight with pagination

I have a WordPress website with a menu similar to this one: Yahoo news, so basically:
a horizontal menu with two levels, the first with main categories the second with sub-categories (in the "Home" menu item, the subcategory is the page "about us".
I am using the build-in Menu of WordPress
The problem I have is with the pagination and also with the search form:
When I am in the Home Page and I
click any pagination number, the
subcategories of "Home" menu item
disappears, and most importantly,
the "Home" menu item is no longer highlighted.
When I search something, again the
same issue, the "Home" is no
longer highlighted, and there is
no subcategory under "Home" menu
item.
I have found a solution:
1) Open header.php, and add this in the body tag:
<body<?php if ( is_home() || is_search() || is_404() ) { echo ' class="main"';} else { echo '';} ?>>
2) Add a class that target the home class, so:
body.main #main-menu ul li.menu-item-home a {
background: #313B47;
color: white;
}
Now if I am in the home page, or in the search page, or 404 error page, WordPress adds class="main" to the body, so I can easily target the menu item which I want.

Resources