I'm trying to add a tooltip function (on hover) to the following shortcode:
<?php
echo do_shortcode('[um_loggedout]Accedi /<br>Registrati[/um_loggedout]');
?>
I've already created a css class with all the parameters needed, but since I am not
big with php I don't really know how I can make it work.
Anyone can help me? If this detail can be useful I am working via Wordpress.
Thanks,
Ivan
What does that output to the frontend? Can you apply your hover styles to one of the classes generated by the shortcode?
---Update---
So you're trying to create a login form appear when they hover over the logged out text?
If so, I think you can use [ultimatemember form_id=####] to display the login form, you'll need to replace the #### with the login form ID. If the <br> tag in the above example works, why can't you wrap the text in a div?
<?php
echo do_shortcode('[um_loggedout]<div id="display-login-form">Accedi /<br>Registrati</div>[/um_loggedout]'); ?>
Then with jQuery/JavaScript, on hover make the box display?
$('#display-login-form').on('mouseover', function() {
$('[insert form container id here]').show();
})
You'll need some logic/ability to hide it if they change their mind.
Related
I am trying to add a code snippet in Wordpress using the Code Snippet plugin (https://nl.wordpress.org/plugins/code-snippets/).
I want it to make a DIV on my homepage clickable so it will hyperlink to another page. The DIV I want to make clickable is <div class="row theme-project-row"></div>
Screenshots:
Rendered page: https://snipboard.io/AUDaho.jpg
DIV in DevTools: https://snipboard.io/zh9VZj.jpg
Any suggestions on the PHP snippet to add? I already tried finding the DIV in my theme's PHP files but I can not locate it. Sorry in advance for asking stupid questions, I am really not an advanced user but I sincerely would like some help.
Thanks in advance I would really appreciate it.
This is how I would attempt it using a snippet. Make sure to 'activate' it when you save.
add_action( 'wp_head', function () { ?>
<script>
window.onload=function() {
console.log("WE GOT window.onload")
let div = document.getElementById('theme-project').querySelector('.theme-project-row');
console.log("WE GOT div:", div)
// give it a clickable style
div.style.cursor='pointer';
div.addEventListener('click', function() {
location.href='home-page.html'; // or whatever link
}
}
</script>
<?php } );
I'm running a simple wordpress site where there is a possibility for users to log in. I'm now at a point where I want to display different HTML content based on the currently logged in user.
I know that this can be solved by using PHP and I even have a basic knowledge in using PHP but I just don't know where and how to start.
Thanks for every input and best regards
It is quite simple to do this, once you get to know your way around PHP. You can use this by using shortcodes (which, in HTML, you can call with do_shortcode term) so you will be able to use it with shortcodes and in HTML if needed.
You will first have to register a shortcode first. As you said, you only want a different HTML content for logged in users. To create a shortcode open your functions.php file and copy/paste this code:
add_shortcode('EXAMPLE','show_user_content');
function show_user_content($atts,$content = null){
global $post;
if (!is_user_logged_in()){
return "You aren’t allowed to read this. " . wp_login_url( get_permalink($post->ID) ) . ' to view the content';
}
return $content;
}
You can edit the part which returns the error if someone, who isn't logged, wants to view the content and also the EXAMPLE part in the first row - that is the name of your shortcode, so make it unique. This won't go by roles (admin, mod, editor etc) but by the state if someone is logged in.
After that just use [EXAMPLE] Some content [/EXAMPLE] in your post editor. Be aware that you have to use the text editor of the post, not the visual editor (as it doesn't recognize shortcodes).
If you want to implement this in HTML, just use the do_shortcode function:
<?php echo do_shortcode('[EXAMPLE]Hello world![/EXAMPLE]'); ?>
And just put content inside the 'Hello world!' part.
I was wondering could you help me, we currently have an announcement banner across the top of all our webpages which I want to remain apart from one page. A couple of guys did a bit of work for me a put an announcement in which I can edit via Custome Content Type Manager on Wordpress.
In the Header.php the code is there and I'm not sure how to get it to stop appearing on a particular page, the id of the page I DONT want it on is 2664. The code is shown below:
<?php
$gathering_page = get_the_ID();
if( ($gathering_page == 3001 || $gathering_page ==2664) && !(is_front_page()) ){ ?>
I'm not sure if the guys have tried to block it or what this code means.
Any feedback would be appreciated. Thanks
EDIT: This may make it easier; I would like to make a div class disappear on the page named above. the div class is
<div class="snippetHomeTop">
I'm sorry if I did wrong, but have you tried using the is page?
<?php if (is_page('2664')) {
// don´t show content for page ID 2664
} else {
// show content for other pages
}?>
Good Luck
I want to display certain text in all my posts except if it's in this one category. How do I do that? Oh yea I almost forgot I want to include the title of the post in the text. So I think I need to use echo, cat='-5', and or something?? I don't know how to form it though. Thanks!
You could use the Wordpress function in_category(). When you use it inside the loop, it returns true if the current post is a member of the category you passed it.
<?php
if ( in_category('my-category'))
{
// don't output text
} else {
// do output text
}
?>
Do you require the text to be completely locked away, or just hidden from view? If you only need it hidden from view (but accessible to anyone who chooses to pry) then you may be able to do it very quickly using css.
If you have coded your theme - or are using someone else's - that adds helpful styles into the header, you may have a lot to work with already. For example, this is a body declaration generated by the Thematic theme:
<body class="wordpress y2011 m01 d31 h12 archive category category-orthopaedics">
Say you have a chunk of content to hide:
<div class="text_to_hide">This is what gets hidden.</div>
Then you declare the CSS as:
.category-orthopaedics .text_to_hide { display: none; }
How do I add a div between the header area and content area of a thesis theme. What is the code I need to write in custom_functions.php file to do this? If that's not the place, where do I need to make changes to get this done?
In your custom_functions.php file add the following code:
function my_div()
{
echo '<div>Some new DIV between the header and content</div>';
}
add_action('thesis_hook_after_header', 'my_div');
You my want to reference Thesis Hooks and the DIYThemes site for more specific Thesis help.
You'll need to edit the theme files. Probably the header.php and the one where the one which contains the body. Before you fire off questions like this, please read through http://codex.wordpress.org/Theme_Development.
One really easy way, is to use Thesis Openhooks. Select the one that's between the header and the content area. I use that method all the time, especially for images. Inside the hook, all you have to do is type the HTML code for the DIV (I tried to type it here, but the code disappeared after I posted the comment) and then I can add CSS code to it in custom.css. Hope this helps :)