Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display code from xprofile field


  • Round World Travels
    Participant

    @gearupandplay

    Hi, I have created a profile field for a user to input a ad code which in turn I would like to display on their blog posts.

    Normally I would use something like this to display the field on the blog post.
    <?php echo xprofile_get_field_data( 'AD', get_the_author_id()) ?>

    It don’t work however. Is there a way I can fetch the code and actually have it run on the blog post.

    Thanks,
    Michael

Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    get_the_author_ID() has been deprecated. Try this instead:

    echo xprofile_get_field_data( 'AD', get_the_author_meta( 'ID' ) );


    Round World Travels
    Participant

    @gearupandplay

    Hi @henrywright, thanks for responding. So, that works in displaying the code but it don’t actually fetch the ad. It just shows the script code. I’m wondering if I can actually make it run the script. It is a Adsense Script.

    Michael


    Henry Wright
    Moderator

    @henrywright

    What is the script language? If JavaScript then you will need to surround it with <script> tags.


    Round World Travels
    Participant

    @gearupandplay

    Thanks again Henry, tried what you said like this but couldn’t get it to work.
    <script><?php echo xprofile_get_field_data('AD', get_the_author_meta( 'ID' ) ); ?></script>

    Do I need to take out the script tags from the profile field. However I notice there are two sets of them. The code on the buddypress profile field form looks like this:

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-3864028244866881"
         data-ad-slot="9938917139"
         data-ad-format="auto"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    Round World Travels
    Participant

    @gearupandplay

    Any other suggestions? Right now the script actually shows up as text on the blog post with script tags and all that were pulled from the profile field.


    Round World Travels
    Participant

    @gearupandplay

    Just tried a html only ad and it also just displays the text code of the ad.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar