In wordpress widgets I have a "Image" widget. It has:
Title
The image you uploaded or want to upload
The size
The link
The link text
Now I want to know, is there a hook or something i can use to grab that "link" from the saved widget? See below. On the 4th line I want to display the link from that image widget here where it says THIS IS WHERE I WANT TO GET THAT LINK HERE.
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Other Serviecs Page Widget',
'before_widget' => '<a href="THIS IS WHERE I WANT TO GET THAT LINK HERE"><div class="col-sm-6 col-md-3">
<div class="add-box-main"> ',
'after_widget' => '<div class="box-bottom"> </div>
</div>
</div>',
'before_title' => '<div class="box-heading"> <img src="../wp-content/uploads/2014/10/OS-LOGO.jpg" class="img-responsive" alt=""><h2>',
'after_title' => '</h2></div>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Other Serviecs Page Bottom Widget',
'before_widget' => '</a>',
'after_widget' => '',
'before_title' => '<h1 class="hide">',
'after_title' => '</h1>',
));
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 );
Have you looked at wp_get_attachment_url in the Wordpress codex? Here's the link: http://codex.wordpress.org/Function_Reference/wp_get_attachment_url
That will return the full path to the image file assuming that there's a loop running.
Let me know if that helps.
Related
I'm going through a client's site using Siteimprove's chrome extension to test for compliance. I'm getting a "Landmarks with identical names" error on two asides in one sidebar area. In the register sidebar code in functions.php, I have:
'before_widget' => '<aside id="%1$s" class="widget %2$s" aria-label="Job Openings and Events">',
This is working and assigning the label, but there are two widgets in this sidebar (a text widget and events list widget) and Wordpress is creating an aside for each with the same label. Is there some sort of nth assignment or something I can do to assign each aside in this sidebar with a different label to prevent redundancy?
See this example,
function my_edit_widget_func($params) {
$params[0]['before_widget'] = '<aside id="%1$s" class="widget %2$s" aria-label="' . $params[0]['widget_name'] . '">' ;
return $params;
}
add_filter('dynamic_sidebar_params', 'my_edit_widget_func');
Hope this will helps you. For more information please visit.
dynamic_sidebar Function to Generate Class
Add class to specific widget in WordPress
Wordpress : Change title of sidebar widget dynamically
Ask
register_sidebar(array(
'name' => 'Footer #2',
'id' => 'footer2',
'description' => 'Footer widget 2',
'before_widget' => '<aside role="complementary" id="%1$s" class="widget-content footer-widget" aria-label="[title]">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title footer-widget-title">',
'after_title' => '</h2>' ,
));
function stp_accessibility_widget_func($params) {
$name = isset($params[0]['widget_name']) ? $params[0]['widget_name'] : "";
$params[0]['before_widget'] = str_replace('[title]', esc_attr($name), $params[0]['before_widget'] );
return $params;
}
add_filter('dynamic_sidebar_params', 'stp_accessibility_widget_func');
Use this solution it will add aria-label in all the widgets
I have a sidebar in WordPress I've registered like so:
register_sidebar(array(
'id' => '404',
'name' => __('404', 'jointstheme'),
'description' => __('The 404 sidebar.', 'jointstheme'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
I duplicated my existing 'sidebar.php' file and created a file called: sidebar-404.php.
I also added the call to my sidebar in the 404 page template like so:
<?php get_sidebar('404'); ?>
Yet for some reason, my theme keeps defaulting to the default sidebar.
Anyone have any ideas what might be going on?
Thanks!
When you register a sidebar in your functions.php file and want to use the widget manager in from the admin panel, you need to use dynamic siderbars not get_sidebar. get_sidebar will only display the widgets that are coded into the file.
Instead of <?php get_sidebar('404'); ?> you should have something like <?php dynamic_sidebar( '404' ); ?>
Hello Guys Im trying to put a search box in my menubar and I was able to do it BUT how can I use the woocommerce search product instead??
heres my current Code in the function.php:
add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li>' . get_search_form( false ) . '</li>';
return $items;
}
I want to put Woocommerce_product_search in my MENUBAR anybody can help me.
SOrry for the ENglish im really not good in it.
Register a Sidebar in your Functions.php and then add the sidebar into your container where you want the search box to appear. Then add the Woocommerce Search Widget to this sidebar inside the Wordpress Admin interface.
Add this to Functions.php:
register_sidebar(array(
'id' => 'search-widget',
'name' => __('Search Widget'),
'description' => __('Drag search widget to this container'),
'before_widget' => '<article id="%1$s" class="widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h6>',
'after_title' => '</h6>'
));
}
Add this to your Header.php or whichever file contains the code where the search box needs to go:
<?php dynamic_sidebar("search-widget"); ?>
I have used the following PHP code to register a sidebar:
register_sidebar(array(
'name' => 'Owner\'s main page intro left sidebar.',
'id' => 'main-left-sidebar',
'description' => 'This is the main side bar of the theme i.e. the information of the author on the index page will be displayed using it. Note: It MUST have a single text widget or otherwise it may distort the theme',
'before_widget' => '',
'after_widget' => '</p>',
'before_title' => '<div class="porse"><h3 id="titlehead">',
'after_title' => '</h3></div><p class="porse-lead">'
));
So that when I add a widget (I'm working with a text widget), it generates something like the following:
<div class="porse">
<h3 id="titlehead">I'm Kamran Ahmed</h3>
</div>
<p class="porse-lead">I make websites. I help small businesses, start-ups, individuals, and fellow web agencies make the most of their web presence.</p>
But whenever I add a widget to the sidebar, it keeps producing the following markup:
<div class="porse">
<h3 id="titlehead">I am Kamran Ahmed</h3>
</div>
<p class="porse-lead"> </p>
<div class="textwidget">I make websites. I help small businesses, start-ups, individuals, and fellow web agencies make the most of their web presence.</div>
<p></p>
Can anyone please tell me, what I'm doing wrong here. Why isn't it producing the markup that I want?
You can't use <div> tags inside <p> tags.
Try this instead:
register_sidebar(array(
'name' => 'Owner\'s main page intro left sidebar.',
'id' => 'main-left-sidebar',
'description' => 'This is the main side bar of the theme i.e. the information of the author on the index page will be displayed using it. Note: It MUST have a single text widget or otherwise it may distort the theme',
'before_widget' => '',
'after_widget' => '</div>',
'before_title' => '<div class="porse"><h3 id="titlehead">',
'after_title' => '</h3></div><div class="porse-lead">'
));
I want to register a sidebar with my html custom title on Widgets area.
My register widget function like ;
register_sidebar(array(
'name' => __( '<img src="'.$keepAdminImages.'/_assets/_img/keepSignature.png" />' ),
'id' => 'keepSense-Left',
'description' => __( 'keepSense Temanızda Sol alanda yer alacak bileşenlerinizi bu kısma sürükleyip bırakabilirsiniz.' ),
'before_title' => '<h1>',
'after_title' => '</h1>'
));
$keepAdminImages = get_bloginfo('template_url');
Its output seems like : http://prntscr.com/tbbmw How can use some html tag in that area ? Any help ? Thanks.
Fatih, i think you can not use images on admin area. Did you check http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/widgets.php#L0 ?