Is it possible to use PHP's str_replace()
function to target only select DIV's within a page (identified by ID or classes for example)?
The situation: I'm using the following str_replace()
function to convert all checkboxes in my Wordpress Post Editor - Categories metabox to use radio buttons instead so authors of my site can post only in one category.
The below code is working (on WP3.5.1) but it replaces the code for other checkbox elements on the same page. Is there any way to target only the category metabox?
// Select only one category on post page
if(strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') ||
strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php'))
{
ob_start('one_category_only');
}
function one_category_only($content) {
$content = str_replace('type="checkbox" ', 'type="radio" ', $content);
return $content;
}