Show/hide page content based on cookie from url parameter
I am looking to show some content on a page based on the on the parameter in a link.
If a link is given to a user https://www.examplesite.com/example-page?feeback=1
then they will see the content of the page, if not using the link, then users will not see the content.
Additionally, I need the users of the link to be able to look on other pages and return to the page where the content is hidden/shown and still see the content.
I have set a cookie in functions.php, that will expire in 30days
add_action('init', 'set_feedback_cookie');
function set_feedback_cookie () {
if (isset($_GET['feedback'])) {
$name = 'client_feedback';
$value=$_GET['feedback'];
setcookie($name, $value, time()+60*60*24*30, "/example-page/", "examplesite.com" , "true" );
}
The cookie is loaded on to the page (as seen in chrome dev tools),
Now i just need to hide the content on the page. The section to hide has an id #form__feedback.
What code do i need to add to get the content to hide, is this code added to functions.php or to a page template?
Is php or jQuery the best option for doing this?
Leave an answer