Archivio

Posts Tagged ‘wordpress’

How to add_submenu_page() passing a $variable (parameter=value) with called function

agosto 21, 2013 1 commento

Since in WordPress you cannot pass directly a parameter into the callback function called by the add_submenu_page, I have figured out another simple way to do it.

My problem was to pass a simple parameter into a sub-menu page, something like:
myblog.com/wp-admin/page=my-sub-menu1?parameter=value

You cannot pass value into the callback function, so you CAN’T do this:

add_submenu_page(parent_slug, page_title2, menu_title2, capability, my-sub-menu2, myfunction1(parameter=value )  );

I’ve tried also a secondary function with a wp_redirect, but was not working because headers were alreay set.
Instead I found this solution:

add_submenu_page( parent_slug, page_title, menu_title, capability, my-sub-menu1, myfunction1 );

add_submenu_page(parent_slug, page_title2, menu_title2, capability, my-sub-menu2, myfunction2 );

function myfunction1() {
// Do something
}

function myfunction2() {

     $_REQUEST[‘parameter’] = “value”;

myfunction1(); // Call the original function, but with your parameter set.

}

You just call a secondary function, set the $_REQUEST[‘parameter’] and then call the original function. That’s all !

How to have sticky pages on wordpess

agosto 17, 2013 Lascia un commento

You have to change a single line (#137) in  wp-admin/includes/meta-boxes.php

from:

<?php if ( $post_type == ‘post’ && current_user_can( ‘edit_others_posts’ ) ) : ?>

to:

<?php if ( in_array( $post_type, (array) apply_filters( ‘sticky_post_types’, array( ‘post’, ‘page’  )  ) ) && current_user_can( ‘edit_others_posts’ ) ) : ?>

There is an open thread on the Core Trac WordPress website, with also my contribute:
http://core.trac.wordpress.org/ticket/12702#

Using microdata RDFa with Breadcrumb NavXT 4.4 (schema.org)

agosto 8, 2013 3 commenti

I’ve worked hard to accomplish to set up RDFa microdata in Breadcrumb NavXT plugin on my WordPress site (http://gak.it) for a structured data breadcrumb (for Google seo and serp).
I’ve searched on internet and found these very interesting articles:

But they where not working because of the new 4.3 version  of Breadcrumb NavXT. Quoting from this article:

Since Breadcrumb NavXT 4.3.0, all settings that can contain HTML are passed through wp_kses(). With this change, only a basic set of acceptable tags and properties within tags were allowed. […] . However, with Breadcrumb NavXT 4.4, a new filter bcn_allowed_html has been introduced to fix this issue.

Finally the right idea was taken from the very same article, and combining all toghether i’ve solved the problem.

At body tag you have to add the red lines. Blue lines are optional. They are an if statemant that check if the plugin is active):

<body <?php if(function_exists(‘bcn_display’)){?>
itemscope itemtype=”http://schema.org/WebPage&#8221;
<?php }?>
<?php body_class(); ?> id=”body”>

In your theme file (in my case is in header.php), near your breadcrumb section you have to wrote the xmlns file.
Red lines are my lines. But you have to have also the blue lines that display the Breadcrumb via bcn_display() function.

<div itemprop=”breadcrumb”>
<span xmlns:v=”http://rdf.data-vocabulary.org/#”&gt;
<?php if(function_exists(‘bcn_display’))
{ bcn_display(); }?>
</span>
</div>

From version 4.3 you also have to set a filter in your function.php theme file, otherwise all the extra-attributes (itemscope, :v,  etc) will be removed. I’ve worked hard these day to finally find this working code (a little be redundant, but i preferred to add more values to tags).

In function.php of your theme you have to add all the following lines:

// 42 – 08/08/2013 – adding a tag to the allowed HTML list for Breadcrumb NavXT

function my_bcn_allowed_html($allowed_html)
{
$allowed_html[‘li’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘span’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘div’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘a’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true,
‘href’ => true
);

return $allowed_html;
}
add_filter(‘bcn_allowed_html’, ‘my_bcn_allowed_html’);

if you know what are you doing you can also add or remove some attribute, but be carefull, these values override the default ones, so e.g. if you remove the href attribute from the <a> tag it will be automatically stripped. It will be indeed no more recognized because the default values where overriden.

For verifying the correct results, you can use the Google Structured Data Testing Tool

Enjoy ^_^