Adding adsense unit under related listing

This topic contains 18 replies, has 3 voices, and was last updated by  Guust 7 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #411612

    eic2010
    Full Member
    Post count: 209

    Hi
    On my listing detail page I have about, photos, map, related listed in a list view. I would like to place an adsense code under the related listing. I saw the following code in the forum:

    add_action(‘geodir_after_detail_page_more_info’ , ‘add_adsense’, 10);
    function add_adsense(){
    echo “adsense code here”;
    }

    but I do not know how to change this so that it goes under related listing. Also where do I place this code?
    Thanks in advance!

    #411616

    Guust
    Moderator
    Post count: 29970

    That code will place “adsense code here” in the sidebar of the Detail page.
    If you want to add adsense on the bottom of the Detail page, activate the bottom widget section and add a text widget with your code.
    See https://wpgeodirectory.com/docs/layout/#directory

    If you want to use the above code, review https://wpgeodirectory.com/docs/useful-plugins/#snippets

    Thanks

    #411620

    eic2010
    Full Member
    Post count: 209

    Thanks for the quick reply. Ideally though I want the adsense to be contained within the actual listing. If I use the widget on the bottom it goes across the full width. If you look at my screen shot attached you will see where the adsense has gone and where I ideally would like it.
    Thanks again for your help!

    #411623

    Guust
    Moderator
    Post count: 29970

    You can edit the template to move the bottom section to where you want it.
    See https://wpgeodirectory.com/docs/customizing-geodirectory-templates/

    I’ll get a developer to have a look at your question too, there may be a hook for that.

    #411627

    eic2010
    Full Member
    Post count: 209

    Hi
    Yes that would be great thank you. I did create a html field (sceenshot attached) which will add it but it involves adding it each time to each listing – something I dont want. Not sure if there is a way of having this code always in there by default?

    #411629

    eic2010
    Full Member
    Post count: 209

    I’m not overly confident changing templates!

    #411637

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hello,

    it would be possible to put it IN the related listings tab but i believe that is against the adsens T&C. If i’m not wrong the ad can’t be loaded in a hidden location, so unless u had the tabs showing as a list view it might not be the best idea.

    Let me know what you want to do.

    Thanks,

    Stiofan

    #411648

    eic2010
    Full Member
    Post count: 209

    Yes I do have it as a list view. I dont want it in the related listings but underneath it

    #411659

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Not tested but something like this:

    
    
    add_action('geodir_after_tab_content','_my_tab_content_after',10,1);
    function _my_tab_content_after($tab){
    if($tab== 'related_listing'){
    echo "adsense code here";
    }
    }

    Thanks,

    Stiofan

    #411665

    eic2010
    Full Member
    Post count: 209

    Apologies for my ignorance but where do I put that?

    #411673

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    No probs, the best way would be to use the code snippets plugin: https://wpgeodirectory.com/docs/useful-plugins/#snippets

    Thanks,

    Stiofan

    #412626

    eic2010
    Full Member
    Post count: 209

    Hi again

    Ive tried that and the plugin works great and goes where I want it but when I put the adsense code into the add function I get “The snippet has been deactivated due to an error on line 5:
    syntax error, unexpected ‘Unit’ (T_STRING), expecting ‘(‘

    the adsense code is

    <script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
    <!– Link Unit Responsive –>
    <ins class=”adsbygoogle”
    style=”display:block”
    data-ad-client=”ca-pub-****************”
    data-ad-slot=”***********”
    data-ad-format=”link”></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>”;
    }
    }

    so the code I entered looks like:

    add_action(‘geodir_after_tab_content’,’_my_tab_content_after’,10,1);
    function _my_tab_content_after($tab){
    if($tab== ‘related_listing’){
    echo “<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
    <!– Link Unit Responsive –>
    <ins class=”adsbygoogle”
    style=”display:block”
    data-ad-client=”ca-pub-****************”
    data-ad-slot=”***********”
    data-ad-format=”link”></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>”;
    }
    }

    I tried removing line 5 but then just got more error messages.

    Any ideas?

    Thanks again for your help, much appreciated!

    #412686

    Guust
    Moderator
    Post count: 29970

    Make sure not to use curly quotes, try replacing all quotes by re-entering them using Code Snippets. Often when copying from somewhere else, the straight quotes changes to curly quotes.

    If that does not work, please post your URL and WP admin details in a private reply and we will have a look.

    Thanks

    #413005

    eic2010
    Full Member
    Post count: 209

    Ive tried that but now I get
    The snippet has been deactivated due to an error on line 1:
    syntax error, unexpected ‘<‘

    #413011

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    If that does not work, please post your URL and WP admin details in a private reply and we will have a look.

    Stiofan

Viewing 15 posts - 1 through 15 (of 19 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount