Jump to content

string in wordpress function


BRIK

Recommended Posts

Okay, not sure what I'm doing. Thanks for your help in the past. This code should set a page class. If a visitor comes from one specific site then the page class gets set to one thing, if they come from any other site it will get set to the default.


function custom_body_classes($classes) { //wordpress thesis theme hook function - ok
switch( wp_get_referer()) {  //getting the referring URL
case 'http://www.thereferringsite.com/' : //this is the URL i am matching
		$classes[] = "diyc"; //this is the class of the page i want to use if condition is met - ok
		return $classes;
	break;
default :
	/* still need to add this*/ //no worries about this, i'll figure out what I need here - ok
	break;
}
}
add_filter('thesis_body_classes','custom_body_classes'); //this is how I add the code via a hook into wordpress with thesis theme - ok

 

The problem is I want to class to be set when coming from ANY page not just the root. Right now this is working but the referrer must match exactly. I want the referrer to be http://www.thereferringsite.com/*.* so to speak.  would i use stristr()? How would the syntax go?

 

Any suggestions for a noob?? be kind

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/194805-string-in-wordpress-function/
Share on other sites

This is what is working for me. It hides the menu when coming in from a particular referrer but shows it again as the person navigates the site. never hides the menu for anyone else.

function custom_body_classes($classes) { //wordpress thesis theme hook function - ok

$ref1 = parse_url(wp_get_referer()); //getting the referring URL
switch( $ref1["host"] ) {  //looking only at the host
case 'www.thedoman.com' : //this is the host url i am matching
		$classes[] = "diyc"; //this is the class of the page i want to use if condition is met
		return $classes;
	break;
default :
		return $classes;
	break;
}
}
add_filter('thesis_body_classes','custom_body_classes'); //this is how I add the code via a hook into wordpress with thesis theme

 

and my .css

.diyc .menu .tab-1 {display:none;}

 

This will only work with wordpress using the thesis theme

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.